From patchwork Tue Sep 21 13:30:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12507853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 322C9C433FE for ; Tue, 21 Sep 2021 13:31:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C5BD6109E for ; Tue, 21 Sep 2021 13:31:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233180AbhIUNc5 (ORCPT ); Tue, 21 Sep 2021 09:32:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:52446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233231AbhIUNcy (ORCPT ); Tue, 21 Sep 2021 09:32:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DFD6B6109E; Tue, 21 Sep 2021 13:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632231085; bh=TUpkICjorOrJWgOQ0TRLVjF3PxXz2EgDQ3fqCrInApo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lYchrwkOpmtTYMgFhFj9zfdJBaz1q0Z9oxMPR70PGI+O7oMDJ0zK3Ec0asDKYhqe2 C2/3IIik8dlSIPjrwiDyDEhs5K3AsJFlLUX5HGkrUY1GGIYOGKFtGLv4XJ70cqNSYN wjxktqFNc1NM4U/X3AgFXWizrzjQoRcSp0rJhOee4N5p1dKWKvlErr7+XXTv0xXMyC Qgoy/ctWGL0PrIRUstq8IalBxwguI2sXQGnu8w/+ekWuv+NEkv14Z30HQ+ZPJI3o3I 2vk0Tshh46AcsPcF1zpNOzVeMdwA1NzgL03uHTbIUQuuSbbvcEnXOKOR7LXc9ttoEk asIaKQXMyUUZA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1mSfrp-0003bN-A4; Tue, 21 Sep 2021 15:31:25 +0200 From: Johan Hovold To: Johan Hovold Cc: Himadri Pandya , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] USB: serial: kl5kusb105: clean up line-status handling Date: Tue, 21 Sep 2021 15:30:07 +0200 Message-Id: <20210921133009.13739-2-johan@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210921133009.13739-1-johan@kernel.org> References: <20210921133009.13739-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Clean up the line-status handling by dropping redundant initialisations and returning early on errors. Signed-off-by: Johan Hovold --- drivers/usb/serial/kl5kusb105.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index 72d3920c9c48..7681671ddb79 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c @@ -172,8 +172,6 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, u8 status_buf[KLSI_STATUSBUF_LEN]; __u16 status; - status_buf[0] = 0xff; - status_buf[1] = 0xff; rc = usb_control_msg_recv(port->serial->dev, 0, KL5KUSB105A_SIO_POLL, USB_TYPE_VENDOR | USB_DIR_IN, @@ -184,16 +182,17 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, GFP_KERNEL); if (rc) { dev_err(&port->dev, "reading line status failed: %d\n", rc); - } else { - status = get_unaligned_le16(status_buf); + return rc; + } - dev_dbg(&port->dev, "read status %02x %02x\n", - status_buf[0], status_buf[1]); + status = get_unaligned_le16(status_buf); - *line_state_p = klsi_105_status2linestate(status); - } + dev_dbg(&port->dev, "read status %02x %02x\n", + status_buf[0], status_buf[1]); - return rc; + *line_state_p = klsi_105_status2linestate(status); + + return 0; } From patchwork Tue Sep 21 13:30:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12507855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEB72C4332F for ; Tue, 21 Sep 2021 13:31:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D72346115A for ; Tue, 21 Sep 2021 13:31:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233195AbhIUNc6 (ORCPT ); Tue, 21 Sep 2021 09:32:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:52448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233193AbhIUNcy (ORCPT ); Tue, 21 Sep 2021 09:32:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E55BA6115A; Tue, 21 Sep 2021 13:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632231085; bh=prOPIYWELr6nmKB42YtpCDelWSZ0w61BxUEMc2pOTJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vnyb4xBYTqQ2IrnY850MvsQxkxndpcVGwEqfoidzrLyi6bfA8NQXbhsQPs67lNGPT //hxuyYbViPZEoVExLby63fq3qtiOsAAiTCMMfr4HOD4dlZzwx/IzIhB+fPfc9qQap S7QmrfeZyUPDAjThLMkhd50n8IWkkmsLfQY7Ste04FvFE7kykkmQIo8TxPC6NYiqFo 8OBdBshBxU2fG4hDjAk2KV3lxpEQVppA/W3Qz00xea40DyuEl8XS18cYmoiTLW46VD J0L7zpiWE4/6POcIi9XX2CDiUv7kFKebCyD31Zk6qfvwdP2TjwiB93bivITU86r/8V H5bHRwT27xKDw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1mSfrp-0003bP-D3; Tue, 21 Sep 2021 15:31:25 +0200 From: Johan Hovold To: Johan Hovold Cc: Himadri Pandya , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] USB: serial: kl5kusb105: simplify line-status handling Date: Tue, 21 Sep 2021 15:30:08 +0200 Message-Id: <20210921133009.13739-3-johan@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210921133009.13739-1-johan@kernel.org> References: <20210921133009.13739-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Now that the driver is using usb_control_msg_recv(), the line status handling can be simplified further by reading directly into the status variable and doing the endian conversion in place. Signed-off-by: Johan Hovold --- drivers/usb/serial/kl5kusb105.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index 7681671ddb79..99dffbdd3142 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c @@ -163,21 +163,18 @@ static unsigned long klsi_105_status2linestate(const __u16 status) * Read line control via vendor command and return result through * *line_state_p */ -/* It seems that the status buffer has always only 2 bytes length */ -#define KLSI_STATUSBUF_LEN 2 static int klsi_105_get_line_state(struct usb_serial_port *port, unsigned long *line_state_p) { + u16 status; int rc; - u8 status_buf[KLSI_STATUSBUF_LEN]; - __u16 status; rc = usb_control_msg_recv(port->serial->dev, 0, KL5KUSB105A_SIO_POLL, USB_TYPE_VENDOR | USB_DIR_IN, 0, /* value */ 0, /* index */ - status_buf, KLSI_STATUSBUF_LEN, + &status, sizeof(status), 10000, GFP_KERNEL); if (rc) { @@ -185,10 +182,9 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, return rc; } - status = get_unaligned_le16(status_buf); + le16_to_cpus(&status); - dev_dbg(&port->dev, "read status %02x %02x\n", - status_buf[0], status_buf[1]); + dev_dbg(&port->dev, "read status %04x\n", status); *line_state_p = klsi_105_status2linestate(status); From patchwork Tue Sep 21 13:30:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12507859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C110AC433FE for ; Tue, 21 Sep 2021 13:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF92B61184 for ; Tue, 21 Sep 2021 13:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233255AbhIUNc7 (ORCPT ); Tue, 21 Sep 2021 09:32:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:52450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233238AbhIUNcy (ORCPT ); Tue, 21 Sep 2021 09:32:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E785561183; Tue, 21 Sep 2021 13:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632231085; bh=/FskAHTta8BR+nJOSZGpKWzqRfix/jvxVCeWQyU5duk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ag4OBn2icYdE4foTpjoIfZNzfxZUnjgW5hj2wcsN3WiXN1VoWB99W6rW+8T4r9ujZ BGolsSHWxoDht1EpCRtmPH3iWI6eIGdi/w2cpOOxFP0oSoJgUdNexuIhVCJT61p45y gJLbV+3elgiCDr7CJ5pSLHyMlj5y5hQcJExldapGdUiTVY46M/qWyktKbOKTz1H3fc 6bM1ieBi2B92lZ9MjpgK+fhR6NWQBkbFVjNVzzUW07ddYMtB9m0TCSugoiaYOdPoyP txGEVtRvj2NYBTqct4d1mEQ6QvjjWuixp0KeWDf0FiTX1jPHCmZNuVNa4qA4YsKB9A 9o5lKfiDoxDpw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1mSfrp-0003bR-FS; Tue, 21 Sep 2021 15:31:25 +0200 From: Johan Hovold To: Johan Hovold Cc: Himadri Pandya , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] USB: serial: kl5kusb105: drop line-status helper Date: Tue, 21 Sep 2021 15:30:09 +0200 Message-Id: <20210921133009.13739-4-johan@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210921133009.13739-1-johan@kernel.org> References: <20210921133009.13739-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the line-status conversion helper and do the conversion in place instead. Signed-off-by: Johan Hovold --- drivers/usb/serial/kl5kusb105.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index 99dffbdd3142..edcc57bd9b5e 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c @@ -147,24 +147,12 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port, return rc; } -/* translate a 16-bit status value from the device to linux's TIO bits */ -static unsigned long klsi_105_status2linestate(const __u16 status) -{ - unsigned long res = 0; - - res = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0) - | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0) - ; - - return res; -} - /* * Read line control via vendor command and return result through - * *line_state_p + * the state pointer. */ static int klsi_105_get_line_state(struct usb_serial_port *port, - unsigned long *line_state_p) + unsigned long *state) { u16 status; int rc; @@ -186,7 +174,8 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, dev_dbg(&port->dev, "read status %04x\n", status); - *line_state_p = klsi_105_status2linestate(status); + *state = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0) | + ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0); return 0; }