Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7532549ybi; Mon, 8 Jul 2019 23:49:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKGGP6Wiqn44E639JRiWw5dCzB040qn/dW+IMZdnwCtiZoXP2TlWuOPxokDte5K2XmSIoq X-Received: by 2002:a17:90a:30aa:: with SMTP id h39mr30954428pjb.32.1562654988627; Mon, 08 Jul 2019 23:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562654988; cv=none; d=google.com; s=arc-20160816; b=F3jclecf4cU2AVuFAVebIU11gh8+iKWwwDiO/ueHlRfoX3FprXrhwFmzmGxqyJ/LRQ TcUHxhECBtwILA29PtliSwnaxt/uNuSitUY1slX3IwlTeMTwAuyVL0NmwdnI3Av+M5Wv wPLf+mD4K5yHzo4WqX9ITbyl/6ReqR+R2O+olIPn3TK8pCpnP8thJF1EwIZIZrLg/fBZ i1osGvf2ebcBmsUZOgtCp/4f4SG7CIwF6I5XRu8uY57TX2GFcOyfyL0CNhGZrU0YEzdW 1lxB12klZDp7YlTUCHuYCHAQVlCDznMoqS0czcQyJNN8t3wkxFhFk5iavDTLbxUL53pu V6tg== 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=nZ8+FKHY1Ha2zXxtL2uxFgzhj/17xSHdlU3jUbo68SiPSSvv7bow/8ZXyDNev1sSHs mHtcnmzXIjtxWBErepEMH2VGYUb08JCmyNJKWh9OBFxRe7movDJ3SJcU4AxZ21rfteIW QyqafrEgU7DpIkalovmHwWXtVtnbk84TV9+vaZxz87yg75n7eAEQ/ho3wzBHFGxorIIp /nVGqKfk4SPlNMuIcKKHnlKStBwZ8yUJHd5bz/Y+94mpZo0LTlAdAb6Vd74yg02w/aKj IxvWtbZ1HgRXaGhUfongBbnfkcQ35I2866Vfzo/gNo3D7r8o7N3IrR+Fn3U1RyhsYeBB S7Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=Xh+Psw96; 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 e21si8590803pfl.68.2019.07.08.23.49.33; Mon, 08 Jul 2019 23:49:48 -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=Xh+Psw96; 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 S1726519AbfGIGqu (ORCPT + 99 others); Tue, 9 Jul 2019 02:46:50 -0400 Received: from first.geanix.com ([116.203.34.67]:46428 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbfGIGqm (ORCPT ); Tue, 9 Jul 2019 02:46:42 -0400 Received: from zen.localdomain (unknown [85.184.140.241]) by first.geanix.com (Postfix) with ESMTPSA id EDAA3A74D; Tue, 9 Jul 2019 06:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1562654712; bh=RvVOJWjkEeJ3YYiPO/wa5yPU5mMrmddO6c4eYyth5Uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Xh+Psw96ef2VFo2+/cICYD4N15fQLebXyacd6CPPpIAZTZTTF7sunAr/hUS605cUa 3hRBKhO9aRAwGWc9jizOkeEaXULPhvQIdt5//kAclH37OCsMzVeZ3YvfeZm4T3Sfw5 4j6ulCCK/OG8HZvXeckMC3v236DlZrBARwByIajGsnUsgLH46byHxDg+aAgqYrV1Wr reJQDAvCPgM3RVyLUxSbgaN50IAzOpDVzc4/+i+ipqXdBS3UHJ2RGL+afhyFuo/oXf kBNcyWHftM5Ban5dQhDMAaqgKbDZCW1ODxmMcexXHRnrL76PTYcRwe3m8H/vFS7oHY uZZRAe50DnxDQ== 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: [PATCHv2 3/4] tty: n_gsm: add helper to convert mux-num to/from tty-base Date: Tue, 9 Jul 2019 08:46:32 +0200 Message-Id: <20190709064633.45411-3-martin@geanix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190709064633.45411-1-martin@geanix.com> References: <20190709064633.45411-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