Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7178645ybi; Mon, 8 Jul 2019 16:16:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqz43Bi6nxQp2bp65+LbWUAiM1kQpQ12f0DlqANBGaNPT0HJxd9p8ZUzxf8sTCerwG5wFdGX X-Received: by 2002:a17:90a:8c92:: with SMTP id b18mr28342431pjo.97.1562627795424; Mon, 08 Jul 2019 16:16:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562627795; cv=none; d=google.com; s=arc-20160816; b=ndlasTmbuwn1zHkQwY21dNpZ8Ez8eYiI+UGJtso7kQ2EW0gpgLQjSVRnUrHO01KiOO KMnohRUmL1lYspM0wrEqTV9YnMLQIQyQXzuCEgDTIt/X3H2ybD1CMk18cAUwFPUDuZ99 EcZ0xZFq9Cib8X6DzsnMVYikrRS11vABXW4/el6wPmqDqxW8ZQoZGb2SGNdIa1/4Ppj5 7yti5ibdrrXbZGdy+JGWiPCOeUOmA1Jj4r2nwsyYzFHtxyU4YGM+0TQC9l3nqxjdX863 d7gssIuPyCBNBgujuDjfWPkCJltuAGCcsP2Wu4nGBo0FMTc8400cKiY4wBAyIMw2PiCw sMQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3SkMoMjABMqVNrJU9ZDtWJjz/MkJbQVdfCxf+RR/SXE=; b=d5p+nIV3apAaRGKgyKmmUulSc1uVpzVZUZDRYAIGvs2at++L29W0CdvoLCwIlL/9OC dwjRTA/IlFvFCGfu+oRgl3Va8ugGRqlZa5HhzubsW15eK5cXKmLnA7zQOsw5pnYTG6xB wy2sJz3h5nDOb+uhSmXtbeTHJkjaqi0tm5UomckzB01kuhDdAo5q4+yg5l5txfjlXBfu /nq3qMc4UoOUnLbtga1pDt2t58trBuI9Xc8xh9mCyQTkmCRm1Iu4wiipCDxFxOgWsNWE mCnwHPKrJdhiMOgDEnwMpK90B0aOUVN5SMWbxxqKocH/P1SeUfMEVoptemp6XD7i+KmQ tmwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=T0o0S3TN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10si20519688pfc.55.2019.07.08.16.16.17; Mon, 08 Jul 2019 16:16:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=T0o0S3TN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390401AbfGHTD2 (ORCPT + 99 others); Mon, 8 Jul 2019 15:03:28 -0400 Received: from first.geanix.com ([116.203.34.67]:59828 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728461AbfGHTDQ (ORCPT ); Mon, 8 Jul 2019 15:03:16 -0400 Received: from zen.localdomain (unknown [85.184.140.241]) by first.geanix.com (Postfix) with ESMTPSA id 572EEA724; Mon, 8 Jul 2019 19:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1562612508; bh=RvVOJWjkEeJ3YYiPO/wa5yPU5mMrmddO6c4eYyth5Uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T0o0S3TNnyoNYKODjFzhKBNIgIJCd5+ANVjB0KSYw54GzZaW8UFI32nI00aQnixj2 PsPKTBfYETp/yyK1rQ/RdOST9WYAzaOm5wN7rXb1bFVDrG2jWzVGXtArFm6mJ2XK1V rEJEaqBPRqm8K7CKfH9g0aVK/g/QN2EKfNpSJkjbz6ZlonB1PxrogWTY85T7D7k3lN UrAiCRmYJTuLy/AJv9rR41Yo+wLwboGrXxHZEbMuHATOFNpXQ9qTNVZE5T4iEaK58E U162ehoTMyFHtmKIBbNWqiAoY5E1MaXbtg4Fu8sgQM0w9dUyf55fGH7Hz8mPZe4be6 Q7uf+Fg+RoZ6A== From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= To: Greg Kroah-Hartman , Jiri Slaby , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= , =?UTF-8?q?Sean=20Nyekj=C3=A6r?= , Esben Haabendal Subject: [PATCH 3/4] tty: n_gsm: add helper to convert mux-num to/from tty-base Date: Mon, 8 Jul 2019 21:02:51 +0200 Message-Id: <20190708190252.24628-3-martin@geanix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708190252.24628-1-martin@geanix.com> References: <20190708190252.24628-1-martin@geanix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=disabled version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on 884f5ce5917a Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make it obvious how the gsm mux number relates to the virtual tty lines by using helper function instead of shifting 6 bits. Signed-off-by: Martin Hundebøll --- drivers/tty/n_gsm.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index c4e16b31f9ab..cba06063c44a 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2171,6 +2171,16 @@ static inline void mux_put(struct gsm_mux *gsm) kref_put(&gsm->ref, gsm_free_muxr); } +static inline int mux_num_to_base(struct gsm_mux *gsm) +{ + return gsm->num * NUM_DLCI; +} + +static inline unsigned int mux_line_to_num(int line) +{ + return line / NUM_DLCI; +} + /** * gsm_alloc_mux - allocate a mux * @@ -2361,7 +2371,7 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) else { /* Don't register device 0 - this is the control channel and not a usable tty interface */ - base = gsm->num << 6; /* Base for this MUX */ + base = mux_num_to_base(gsm); /* Base for this MUX */ for (i = 1; i < NUM_DLCI; i++) tty_register_device(gsm_tty_driver, base + i, NULL); } @@ -2380,7 +2390,7 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) { int i; - int base = gsm->num << 6; /* Base for this MUX */ + int base = mux_num_to_base(gsm); /* Base for this MUX */ WARN_ON(tty != gsm->tty); for (i = 1; i < NUM_DLCI; i++) @@ -2908,7 +2918,7 @@ static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty) struct gsm_mux *gsm; struct gsm_dlci *dlci; unsigned int line = tty->index; - unsigned int mux = line >> 6; + unsigned int mux = mux_line_to_num(line); bool alloc = false; int ret; -- 2.22.0