From patchwork Mon Oct 24 13:01:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "D. Starke" X-Patchwork-Id: 10313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp657078wru; Mon, 24 Oct 2022 14:20:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5KzZsZ9lx7BExo9f58RzkhHLZ2w2P/MTTIwJ/q0M4L2yByyYybIY9Xex3uQGRRJKOukMRO X-Received: by 2002:a17:90a:3e81:b0:212:cc3c:b02f with SMTP id k1-20020a17090a3e8100b00212cc3cb02fmr23427005pjc.67.1666646401419; Mon, 24 Oct 2022 14:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666646401; cv=none; d=google.com; s=arc-20160816; b=XCcmTsuWpDLIXbgMLkXUadMmKKBWICFKrklCRFYGsCYzXm4DD7sylDR0gX+We8vIXi idB2Aw3dCM7LOs47o9vyhQSmBw8krRR1SIpFK0zAVdhk201TjIry5rzYRIst6LGxIgY8 yfWMFmWMhHVBLRG6TgAS1VyL5BZZ1xkwudjEoIt2Mit8bUy22QWRdyP9VghZZFTAYiS+ 8zXkbhQk2VTy0vctRIKlGDMOHCHX+dUrDmzhHny1UDzr5z+fVbNOfcOudjjck/ey0Irn jVga+OhpQve/2gJNQtuio69L1ad9D4HdG7JVzeLhGbm84QOjJHDv0wa1XcdpTwYQ6xhf ljWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=K2kGQ1uzzqA0xWymbFltF9V6/W7ChuSY3sWXqrXX9m8=; b=PFqhNLQgcxaYFvsoJ/ApuzCWnxROrCx1A0covYYU/b2L6fzSdn+8Gqu6tfDrFdFFkh iZO9G/dsZc0ImyP3yTeeZ5pwPC7PBFm3260TAb0wqwOk9Ci6P1fB57I2ndby4Y9pPlb0 1GyaKYRFg2aVar72LPd+gqRADp8aRccQj625/HS90Ymc7QWtz/W2fKSesB6Lg9WUFfxa f9X8yO/5JgkwxTnuQ8tlfBPQisBYRSdxEMfAFRTcDcBLwIulOxTv7TF32ZRaGSexKtnB rqcWfU4l9N3fSmRuzsEZqf7Z0auDLNQJII4aGZisXsAd1Edwm7p0Yed5W5qdJcPlMzFB gzJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=iCo9+oyt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x21-20020a631715000000b0046f18bdf887si579704pgl.476.2022.10.24.14.19.47; Mon, 24 Oct 2022 14:20:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b=iCo9+oyt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234124AbiJXVR4 (ORCPT + 99 others); Mon, 24 Oct 2022 17:17:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230453AbiJXVRR (ORCPT ); Mon, 24 Oct 2022 17:17:17 -0400 X-Greylist: delayed 1889 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 24 Oct 2022 12:23:18 PDT Received: from mta-65-225.siemens.flowmailer.net (mta-65-225.siemens.flowmailer.net [185.136.65.225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 567852D2D5E for ; Mon, 24 Oct 2022 12:23:18 -0700 (PDT) Received: by mta-65-225.siemens.flowmailer.net with ESMTPSA id 20221024130239ff05e52880d9cf551f for ; Mon, 24 Oct 2022 15:02:39 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=daniel.starke@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc; bh=K2kGQ1uzzqA0xWymbFltF9V6/W7ChuSY3sWXqrXX9m8=; b=iCo9+oytoKkqsi8D6FE1CqIrKRjRBDp0s+x9g85W4BMGVfZAjDlMJCk0M8NCG3YgAXHg1Y UknYlfcxZN7zk9hKtLB/4hNCrwX4cPP/EiBlR3VHPSwIfGqZhCVy1Gh1lXj2/FAVOAvfCHVy ej/gR5+Z+wXC/8GDp9yPdAd/ojYU0=; From: "D. Starke" To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: linux-kernel@vger.kernel.org, Daniel Starke Subject: [PATCH v2 1/3] tty: n_gsm: introduce macro for minimal unit size Date: Mon, 24 Oct 2022 15:01:12 +0200 Message-Id: <20221024130114.2070-1-daniel.starke@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747605416775383764?= X-GMAIL-MSGID: =?utf-8?q?1747605416775383764?= From: Daniel Starke n_gsm has a minimal protocol overhead of 7 bytes. The current code already checks whether the configured MRU/MTU size is at least one byte more than this. Introduce the macro MIN_MTU to make this value more obvious. Signed-off-by: Daniel Starke Reviewed-by: Ilpo Järvinen --- drivers/tty/n_gsm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) v1 -> v2: Incorporated review comments. Link: https://lore.kernel.org/all/fe537e8-7b2-61e2-767d-787b923c7456@linux.intel.com/ diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 5e516f5cac5a..570c40a3d78f 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -89,6 +89,7 @@ module_param(debug, int, 0600); */ #define MAX_MRU 1500 #define MAX_MTU 1500 +#define MIN_MTU (PROT_OVERHEAD + 1) /* SOF, ADDR, CTRL, LEN1, LEN2, ..., FCS, EOF */ #define PROT_OVERHEAD 7 #define GSM_NET_TX_TIMEOUT (HZ*10) @@ -2712,7 +2713,9 @@ static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) if ((c->adaption != 1 && c->adaption != 2) || c->k) return -EOPNOTSUPP; /* Check the MRU/MTU range looks sane */ - if (c->mru > MAX_MRU || c->mtu > MAX_MTU || c->mru < 8 || c->mtu < 8) + if (c->mru < MIN_MTU || c->mtu < MIN_MTU) + return -EINVAL; + if (c->mru > MAX_MRU || c->mtu > MAX_MTU) return -EINVAL; if (c->n2 > 255) return -EINVAL; @@ -3296,7 +3299,7 @@ static int gsm_create_network(struct gsm_dlci *dlci, struct gsm_netconfig *nc) return -ENOMEM; } net->mtu = dlci->gsm->mtu; - net->min_mtu = 8; + net->min_mtu = MIN_MTU; net->max_mtu = dlci->gsm->mtu; mux_net = netdev_priv(net); mux_net->dlci = dlci;