Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp175157rwi; Wed, 12 Oct 2022 18:07:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7o3ZqaiJKjpytT8mtzUvuDcygjlbmXUtQOb4nMrEurIJ50uZQvjDvRw2gTPnZRW862D3Zc X-Received: by 2002:a63:5262:0:b0:43b:282d:47ec with SMTP id s34-20020a635262000000b0043b282d47ecmr28272941pgl.577.1665623238115; Wed, 12 Oct 2022 18:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665623238; cv=none; d=google.com; s=arc-20160816; b=NL96TV/BU/cmaV+yOrGr9EayuME+5sTD4TCqXJ7EUX+ZVNme1Y+e/VBeMv3ZeV2mYi p7sXBwe0IKYR/ldFljW+zjrcO6JA0tYPmU0gFyqRDB99P2HgQ9GDZZQ9kn2GmndSzrz8 WvOnJnfZpPjclV2b6F/nt2UfB4T9hGtSOtwc0R8PBIU9He6uoXx9MfIZdAYZ/Dl/J6MQ JvSvIUll3K3jux2uVEKJnHnjy138JUFwtZUT/MMZBvVGhPnZ682qKGEIiabQW73tU+IM HLrydgNiubNZoJwR6yLur0rpKc+yWmxOPyw1F64oCwmC0FfrnaBHqQD0kHOQHgpUXWi1 vi6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SU2OiF2rio7HJIdnOfpqbxdJn4ntvEm2Ld3wEmpXvVI=; b=Tmuzn2viAnEppeDXcR3xGQzHm4lDIO2EZTAJN1TcLugu+R59BAK1xfz7WUidIUveSB Dxjkie0bGJcWAUuurnEb0EmL6p8GcySMUyjhT59MQfiMi39xSUjJIfXsiCvfiIlErQcR 53hnR8YXkI0H+hKPnZ6owjzHq+0xuehDFhGnzLIb8b1yQXsrLBpDT75hSvmYDi2Tg6y3 wcSXNkLmQwJNEsUJVcGCgH2aryaLkBBqHHcbQz8zvZY0fD6Va1LInlSkxZry1bP4T8Us VvqmEWIILSHK8D8Sht92Q0RDghPQ1lpR+Yv5YCRyearS34iIQKTTIMnn8/HMPknwnvJn YFdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NdjLSgFl; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z17-20020a170903019100b0017f97fe774fsi13963160plg.445.2022.10.12.18.07.06; Wed, 12 Oct 2022 18:07:18 -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=@kernel.org header.s=k20201202 header.b=NdjLSgFl; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbiJMAUu (ORCPT + 99 others); Wed, 12 Oct 2022 20:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbiJMATx (ORCPT ); Wed, 12 Oct 2022 20:19:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44BAF18C967; Wed, 12 Oct 2022 17:17:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5828EB81CC2; Thu, 13 Oct 2022 00:17:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DE65C433D6; Thu, 13 Oct 2022 00:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620254; bh=4kmDb3KHHylw+eDUb0jbPSSY6h1B5b/2uzbRSJomm6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NdjLSgFlDEt0ZHelp1ApZWIR1ak4NsmeBzD5EHxrmkX0USBfj5+aaNaUDGVtRMRMc VxFkBsGffLMD6CLL41mWM5Y2ryPuwJgdKfZEixLI1vkh+ftprDqmw0vRTp4QE2W4Qw XDXXlsqt5bPqq/XGUfRBa9TaC9DES2kw9eeDVasjXJq28BX1o+OF7wtzMVWpG26/Z0 czSyc3PXss/6IHmU6R6W0CUSJfQRhT+kNtnmDpHBYlwEHGBo2hucyh9zKEjkKAFV6G aQZBnAUdPT0SV4D74FzKgn6ILHp3pUUaqZ0fCAH9OGkQfCGbFU5cTdOyI9hhdpO5zJ YKX50uZ3muCHA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Daniel Starke , kernel test robot , Greg Kroah-Hartman , Sasha Levin , jirislaby@kernel.org Subject: [PATCH AUTOSEL 6.0 43/67] tty: n_gsm: replace use of gsm_read_ea() with gsm_read_ea_val() Date: Wed, 12 Oct 2022 20:15:24 -0400 Message-Id: <20221013001554.1892206-43-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Daniel Starke [ Upstream commit 669609cea1d294f43efdd8d57ab65927df90e6df ] Replace the use of gsm_read_ea() with gsm_read_ea_val() where applicable to improve code readability and avoid errors like in the past. See first link below for reference. Link: https://lore.kernel.org/all/20220504081733.3494-1-daniel.starke@siemens.com/ Link: https://lore.kernel.org/all/202208222147.WfFRmf1r-lkp@intel.com/ Reported-by: kernel test robot Signed-off-by: Daniel Starke Link: https://lore.kernel.org/r/20220831073800.7459-3-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/n_gsm.c | 95 ++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 01c112e2e214..1ff7f03a12ea 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -1407,18 +1407,12 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen) unsigned int modem = 0; struct gsm_dlci *dlci; int len = clen; - int slen; + int cl = clen; const u8 *dp = data; struct tty_struct *tty; - while (gsm_read_ea(&addr, *dp++) == 0) { - len--; - if (len == 0) - return; - } - /* Must be at least one byte following the EA */ - len--; - if (len <= 0) + len = gsm_read_ea_val(&addr, data, cl); + if (len < 1) return; addr >>= 1; @@ -1427,15 +1421,20 @@ static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen) return; dlci = gsm->dlci[addr]; - slen = len; - while (gsm_read_ea(&modem, *dp++) == 0) { - len--; - if (len == 0) - return; - } - len--; + /* Must be at least one byte following the EA */ + if ((cl - len) < 1) + return; + + dp += len; + cl -= len; + + /* get the modem status */ + len = gsm_read_ea_val(&modem, dp, cl); + if (len < 1) + return; + tty = tty_port_tty_get(&dlci->port); - gsm_process_modem(tty, dlci, modem, slen - len); + gsm_process_modem(tty, dlci, modem, cl); if (tty) { tty_wakeup(tty); tty_kref_put(tty); @@ -1910,11 +1909,10 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen) struct tty_port *port = &dlci->port; struct tty_struct *tty; unsigned int modem = 0; - int len = clen; - int slen = 0; + int len; if (debug & 16) - pr_debug("%d bytes for tty\n", len); + pr_debug("%d bytes for tty\n", clen); switch (dlci->adaption) { /* Unsupported types */ case 4: /* Packetised interruptible data */ @@ -1922,24 +1920,22 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen) case 3: /* Packetised uininterruptible voice/data */ break; case 2: /* Asynchronous serial with line state in each frame */ - while (gsm_read_ea(&modem, *data++) == 0) { - len--; - slen++; - if (len == 0) - return; - } - len--; - slen++; + len = gsm_read_ea_val(&modem, data, clen); + if (len < 1) + return; tty = tty_port_tty_get(port); if (tty) { - gsm_process_modem(tty, dlci, modem, slen); + gsm_process_modem(tty, dlci, modem, len); tty_wakeup(tty); tty_kref_put(tty); } + /* Skip processed modem data */ + data += len; + clen -= len; fallthrough; case 1: /* Line state will go via DLCI 0 controls only */ default: - tty_insert_flip_string(port, data, len); + tty_insert_flip_string(port, data, clen); tty_flip_buffer_push(port); } } @@ -1960,24 +1956,27 @@ static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len) { /* See what command is involved */ unsigned int command = 0; - while (len-- > 0) { - if (gsm_read_ea(&command, *data++) == 1) { - int clen = *data++; - len--; - /* FIXME: this is properly an EA */ - clen >>= 1; - /* Malformed command ? */ - if (clen > len) - return; - if (command & 1) - gsm_control_message(dlci->gsm, command, - data, clen); - else - gsm_control_response(dlci->gsm, command, - data, clen); - return; - } - } + unsigned int clen = 0; + unsigned int dlen; + + /* read the command */ + dlen = gsm_read_ea_val(&command, data, len); + len -= dlen; + data += dlen; + + /* read any control data */ + dlen = gsm_read_ea_val(&clen, data, len); + len -= dlen; + data += dlen; + + /* Malformed command? */ + if (clen > len) + return; + + if (command & 1) + gsm_control_message(dlci->gsm, command, data, clen); + else + gsm_control_response(dlci->gsm, command, data, clen); } /** -- 2.35.1