From patchwork Sun Aug 1 20:31:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himadri Pandya X-Patchwork-Id: 490246 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 7ED3FC4320E for ; Sun, 1 Aug 2021 20:33:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E79961029 for ; Sun, 1 Aug 2021 20:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231707AbhHAUdS (ORCPT ); Sun, 1 Aug 2021 16:33:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbhHAUdR (ORCPT ); Sun, 1 Aug 2021 16:33:17 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5972CC06175F; Sun, 1 Aug 2021 13:33:09 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id t21so17217949plr.13; Sun, 01 Aug 2021 13:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2ku34cnAyfySr5zI5nerb5zYCOk3G/JYtmkF3StscuA=; b=W9fTsbTc3Gs/mwd6ZiD20Ne4v2Jh2jqzhcvdtdQsl6JkdB4hWubMpt2epdEuFh4D2e 0PxlQRraHRwYvGGO3JPizBIAFVCI7k6a4Xosis3g173oRjqTG9+liGaRmKPn8XILuM78 7m56XJZnUpSIz3G9pDQjwxdHaETGmc4fap8zBvyAIugn7zB8k9dTD3D1pRKxsewsfwR+ IaU0DgwFB/fi/fGZAHUSQbjCCJIPn9i/ub39vbnB2oAm63lPXyv9Y0WINd4VmLoQ6eEy EwtP3oPdbqExVGCGww4W6asxJ/f5LIixUASSmuNEGqbXu03UfIpXC77v0Mn0buyqMohu uRyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2ku34cnAyfySr5zI5nerb5zYCOk3G/JYtmkF3StscuA=; b=KEV7u1MSZWrm84GhlIUhOeYjOpB2a1Zbb7nXFFix5Z5CVTsoweSNP4EAX5aD5ebcTw TqlElfkcrPU92KgTBIu+muU89ztznikiAuCDVRaOADlsB7Xq+jLQotdA6H47/0dIhTV5 //or9r2i9nTSfn8rPfjbh7V9uv0DkV9/tzPoq3ddzBdZ33DUXP3fj8YMglyQ3hb3e9eR Ie5tdR2anziiMs4xP2+bGMM1fQCjOZNjUfdedIETehnIKicw4pyBU5gnRWJy58nuFmvO QclAjMeXQdd5cb7ChNUcD+OxifvnUnyq2K2SsGGh21NusDAJk6IWc5+TL5i0IJJmCr6w GlHQ== X-Gm-Message-State: AOAM533yEizKJgi89YTBKxdAwYe1/TXz2003tW9cvJry+j6NOeUakKJE XrtoYCvVxnZ59B61ZNxKOGw= X-Google-Smtp-Source: ABdhPJyLjM34FpwpxdXOyEnCTnCTKE/CJPYY2Uc9jld8n+H3FCClx+e1fw+oIUmSKa6GYcBmNH3aQQ== X-Received: by 2002:a17:903:2444:b029:12c:8eba:fd6a with SMTP id l4-20020a1709032444b029012c8ebafd6amr11677278pls.0.1627849988906; Sun, 01 Aug 2021 13:33:08 -0700 (PDT) Received: from localhost.localdomain ([2402:3a80:15b3:589:f07d:5386:a3c2:3056]) by smtp.gmail.com with ESMTPSA id k10sm8897974pfc.169.2021.08.01.13.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Aug 2021 13:33:08 -0700 (PDT) From: Himadri Pandya To: johan@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Himadri Pandya Subject: [PATCH v2 2/6] USB: serial: cp210x: use usb_control_msg_recv() and usb_control_msg_send() Date: Mon, 2 Aug 2021 02:01:18 +0530 Message-Id: <20210801203122.3515-3-himadrispandya@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210801203122.3515-1-himadrispandya@gmail.com> References: <20210801203122.3515-1-himadrispandya@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The new wrapper functions for usb_control_msg() can accept data from stack with robust error checks. Hence use the wrappers with stack variables for usb transfer buffers to save kernel memory. Signed-off-by: Himadri Pandya --- Changes in v2: - Drop unrelated style fixes --- drivers/usb/serial/cp210x.c | 107 ++++++++++-------------------------- 1 file changed, 30 insertions(+), 77 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 3c80bfbf3bec..b73581fc1768 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -628,29 +628,18 @@ static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req, { struct usb_serial *serial = port->serial; struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - void *dmabuf; int result; - dmabuf = kmalloc(bufsize, GFP_KERNEL); - if (!dmabuf) - return -ENOMEM; - - result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - req, REQTYPE_INTERFACE_TO_HOST, 0, - port_priv->bInterfaceNumber, dmabuf, bufsize, - USB_CTRL_SET_TIMEOUT); - if (result == bufsize) { - memcpy(buf, dmabuf, bufsize); - result = 0; - } else { + result = usb_control_msg_recv(serial->dev, 0, req, + REQTYPE_INTERFACE_TO_HOST, 0, + port_priv->bInterfaceNumber, buf, + bufsize, USB_CTRL_SET_TIMEOUT, + GFP_KERNEL); + if (result) { dev_err(&port->dev, "failed get req 0x%x size %d status: %d\n", req, bufsize, result); - if (result >= 0) - result = -EIO; } - kfree(dmabuf); - return result; } @@ -669,30 +658,17 @@ static int cp210x_read_u8_reg(struct usb_serial_port *port, u8 req, u8 *val) static int cp210x_read_vendor_block(struct usb_serial *serial, u8 type, u16 val, void *buf, int bufsize) { - void *dmabuf; int result; - dmabuf = kmalloc(bufsize, GFP_KERNEL); - if (!dmabuf) - return -ENOMEM; - - result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - CP210X_VENDOR_SPECIFIC, type, val, - cp210x_interface_num(serial), dmabuf, bufsize, - USB_CTRL_GET_TIMEOUT); - if (result == bufsize) { - memcpy(buf, dmabuf, bufsize); - result = 0; - } else { + result = usb_control_msg_recv(serial->dev, 0, CP210X_VENDOR_SPECIFIC, + type, val, cp210x_interface_num(serial), + buf, bufsize, USB_CTRL_GET_TIMEOUT, + GFP_KERNEL); + if (result) { dev_err(&serial->interface->dev, "failed to get vendor val 0x%04x size %d: %d\n", val, bufsize, result); - if (result >= 0) - result = -EIO; } - - kfree(dmabuf); - return result; } @@ -727,21 +703,14 @@ static int cp210x_write_reg_block(struct usb_serial_port *port, u8 req, { struct usb_serial *serial = port->serial; struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - void *dmabuf; int result; - dmabuf = kmemdup(buf, bufsize, GFP_KERNEL); - if (!dmabuf) - return -ENOMEM; + result = usb_control_msg_send(serial->dev, 0, req, + REQTYPE_HOST_TO_INTERFACE, 0, + port_priv->bInterfaceNumber, buf, bufsize, + USB_CTRL_SET_TIMEOUT, GFP_KERNEL); - result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - req, REQTYPE_HOST_TO_INTERFACE, 0, - port_priv->bInterfaceNumber, dmabuf, bufsize, - USB_CTRL_SET_TIMEOUT); - - kfree(dmabuf); - - if (result < 0) { + if (result) { dev_err(&port->dev, "failed set req 0x%x size %d status: %d\n", req, bufsize, result); return result; @@ -770,21 +739,14 @@ static int cp210x_write_u32_reg(struct usb_serial_port *port, u8 req, u32 val) static int cp210x_write_vendor_block(struct usb_serial *serial, u8 type, u16 val, void *buf, int bufsize) { - void *dmabuf; int result; - dmabuf = kmemdup(buf, bufsize, GFP_KERNEL); - if (!dmabuf) - return -ENOMEM; - - result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - CP210X_VENDOR_SPECIFIC, type, val, - cp210x_interface_num(serial), dmabuf, bufsize, - USB_CTRL_SET_TIMEOUT); + result = usb_control_msg_send(serial->dev, 0, CP210X_VENDOR_SPECIFIC, + type, val, cp210x_interface_num(serial), + buf, bufsize, USB_CTRL_SET_TIMEOUT, + GFP_KERNEL); - kfree(dmabuf); - - if (result < 0) { + if (result) { dev_err(&serial->interface->dev, "failed to set vendor val 0x%04x size %d: %d\n", val, bufsize, result); @@ -949,27 +911,18 @@ static int cp210x_get_tx_queue_byte_count(struct usb_serial_port *port, { struct usb_serial *serial = port->serial; struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - struct cp210x_comm_status *sts; + struct cp210x_comm_status sts; int result; - sts = kmalloc(sizeof(*sts), GFP_KERNEL); - if (!sts) - return -ENOMEM; - - result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - CP210X_GET_COMM_STATUS, REQTYPE_INTERFACE_TO_HOST, - 0, port_priv->bInterfaceNumber, sts, sizeof(*sts), - USB_CTRL_GET_TIMEOUT); - if (result == sizeof(*sts)) { - *count = le32_to_cpu(sts->ulAmountInOutQueue); - result = 0; - } else { + result = usb_control_msg_recv(serial->dev, 0, CP210X_GET_COMM_STATUS, + REQTYPE_INTERFACE_TO_HOST, 0, + port_priv->bInterfaceNumber, &sts, + sizeof(sts), USB_CTRL_GET_TIMEOUT, + GFP_KERNEL); + if (result == 0) + *count = le32_to_cpu(sts.ulAmountInOutQueue); + else dev_err(&port->dev, "failed to get comm status: %d\n", result); - if (result >= 0) - result = -EIO; - } - - kfree(sts); return result; } From patchwork Sun Aug 1 20:31:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himadri Pandya X-Patchwork-Id: 490245 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 BB793C4338F for ; Sun, 1 Aug 2021 20:33:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A41D961029 for ; Sun, 1 Aug 2021 20:33:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231684AbhHAUd1 (ORCPT ); Sun, 1 Aug 2021 16:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231896AbhHAUdX (ORCPT ); Sun, 1 Aug 2021 16:33:23 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD68AC061799; Sun, 1 Aug 2021 13:33:15 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id q2so17239486plr.11; Sun, 01 Aug 2021 13:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=m9zvSZe68jgoYggnKmJEwWFOA2wmg629eWtmjh7kzPQ=; b=GyyFElPb6VaE5iyhlk0ZRnk3saewzJXXn+Ou1a3k35wR2JvqeEzv/3nB1wPSXkI2mN dZMmhlEICEOvOlUpo6qoWor7uxXgJKMI+X4w06UUjaf8vK6O9m7z3sub/4sUpi3irVHY cA9vNYsLMRXvZk1+1FJGyOBHrsvBa8e6mtoOsmeJtTxiIhhw2NhXbGKqdEOvBTufo2WU hm8zWnVylpou3xmCg3Da8azGVQ4pWxLHuGu0zge0TJxYnBGod+ojm3CpU0Wr7Y/gGiQx Q5AR3nwPGYi9ln6s+nB0t82cwyTJNq6P+L7+vZk0rApom57Ed6DA/kNNzKnLkCLBf1zY 4Jyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=m9zvSZe68jgoYggnKmJEwWFOA2wmg629eWtmjh7kzPQ=; b=MItT7pJu9M+8hKeiuneFHhUxhIeg3xrUg87aWXz2Jpm/VkLZ4z9pyDnJ93ouFKFPrT qBpXSOZ8D1RD8LIpFxGWl/eq5zV4F/A0LrIDXHths/Os4EQQIbfws6vNVsGlENKLIoQ1 lWYIMD4Qo3HZhC0OOJglsVH68HxmVuPktdmtkjg8UONvGu4I7cLy3ncJ1qi5WWDBm876 lJJe06O9Zvfne/CVeOktEPHp1D073oHg9CjWVBQrOojrYbBIF+Y8QJWsKgK7UVo3XOlW qG4kuITlkm/67s0b9aopYOCfsYxbMo6wjhBZ27fSyQOuK0aM9M9TUleQxflvW2DmFuYQ uvcg== X-Gm-Message-State: AOAM532Uk0txaP72++vnSTbbpg/URNDd+QEdBBdo0e0qBkBBSz+q7Mqc i9d/1IG6YhoCNxY9MHE4piw= X-Google-Smtp-Source: ABdhPJwjuEigkpTgbKlBbSTxIAxuAg+D4dHm8eczLtD7GX+Pdf/UgLW47NVvHZqT2j1mPDBPEyrrhg== X-Received: by 2002:a63:504a:: with SMTP id q10mr11139668pgl.383.1627849995245; Sun, 01 Aug 2021 13:33:15 -0700 (PDT) Received: from localhost.localdomain ([2402:3a80:15b3:589:f07d:5386:a3c2:3056]) by smtp.gmail.com with ESMTPSA id k10sm8897974pfc.169.2021.08.01.13.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Aug 2021 13:33:14 -0700 (PDT) From: Himadri Pandya To: johan@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Himadri Pandya Subject: [PATCH v2 4/6] USB: serial: ftdi_sio: use usb_control_msg_recv() Date: Mon, 2 Aug 2021 02:01:20 +0530 Message-Id: <20210801203122.3515-5-himadrispandya@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210801203122.3515-1-himadrispandya@gmail.com> References: <20210801203122.3515-1-himadrispandya@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org usb_control_msg_recv() nicely wraps usb_control_msg() and removes the compulsion of using dma buffers for usb messages. It also includes proper error check for possible short read. So use the wrapper and remove dma buffers from the callers. Signed-off-by: Himadri Pandya --- Changes in v2: - Drop unnecessary use of wrappers --- drivers/usb/serial/ftdi_sio.c | 53 ++++++++++------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 4a1f3a95d017..d4c61568b549 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -1436,27 +1436,15 @@ static int _read_latency_timer(struct usb_serial_port *port) { struct ftdi_private *priv = usb_get_serial_port_data(port); struct usb_device *udev = port->serial->dev; - unsigned char *buf; + u8 buf; int rv; - buf = kmalloc(1, GFP_KERNEL); - if (!buf) - return -ENOMEM; - - rv = usb_control_msg(udev, - usb_rcvctrlpipe(udev, 0), - FTDI_SIO_GET_LATENCY_TIMER_REQUEST, - FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, - 0, priv->interface, - buf, 1, WDR_TIMEOUT); - if (rv < 1) { - if (rv >= 0) - rv = -EIO; - } else { - rv = buf[0]; - } - - kfree(buf); + rv = usb_control_msg_recv(udev, 0, FTDI_SIO_GET_LATENCY_TIMER_REQUEST, + FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, 0, + priv->interface, &buf, 1, WDR_TIMEOUT, + GFP_KERNEL); + if (rv == 0) + rv = buf; return rv; } @@ -1851,32 +1839,21 @@ static int ftdi_read_cbus_pins(struct usb_serial_port *port) { struct ftdi_private *priv = usb_get_serial_port_data(port); struct usb_serial *serial = port->serial; - unsigned char *buf; + u8 buf; int result; result = usb_autopm_get_interface(serial->interface); if (result) return result; - buf = kmalloc(1, GFP_KERNEL); - if (!buf) { - usb_autopm_put_interface(serial->interface); - return -ENOMEM; - } - - result = usb_control_msg(serial->dev, - usb_rcvctrlpipe(serial->dev, 0), - FTDI_SIO_READ_PINS_REQUEST, - FTDI_SIO_READ_PINS_REQUEST_TYPE, 0, - priv->interface, buf, 1, WDR_TIMEOUT); - if (result < 1) { - if (result >= 0) - result = -EIO; - } else { - result = buf[0]; - } + result = usb_control_msg_recv(serial->dev, 0, + FTDI_SIO_READ_PINS_REQUEST, + FTDI_SIO_READ_PINS_REQUEST_TYPE, 0, + priv->interface, &buf, 1, WDR_TIMEOUT, + GFP_KERNEL); + if (result == 0) + result = buf; - kfree(buf); usb_autopm_put_interface(serial->interface); return result; From patchwork Sun Aug 1 20:31:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himadri Pandya X-Patchwork-Id: 490244 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 247F4C432BE for ; Sun, 1 Aug 2021 20:33:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09B0761057 for ; Sun, 1 Aug 2021 20:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232034AbhHAUdb (ORCPT ); Sun, 1 Aug 2021 16:33:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231872AbhHAUda (ORCPT ); Sun, 1 Aug 2021 16:33:30 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9408BC06175F; Sun, 1 Aug 2021 13:33:21 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id b6so22480519pji.4; Sun, 01 Aug 2021 13:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fBZqElFDWoJRba//NR2LkUGnReQMVCu2fGdHFbNTSAA=; b=W9GRiK75FflUy+E6dFVTj5BSu4ZsbqxJvPwtta00h+zyQ3xELbzLhMnsPIpJQVM3x0 JAMtpysJnSPU5gV/6eKz7UTFYIRyXQIU+RRmy6atjfK+YPQV89eNqaB/AbnyMDNzEmxC QjvI0uraRpb+sekb7qITDOTUAWb+CY4pB53md0H4uUjp1wpRC5M6XvS3I6ioVsdZOdgH DJ//wYpuXlxWdln3uIZmlvY1NtZPiXNkVPHu4SIYvoceq/FmmpWi9DUFifCGJj2NulyS nM2EYkDs0mVpksAkl2LWP1e80VfvOlP5PWZ1NyeHmCdAQ9qeXTTcEN84j470nzqxJWSO IjPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fBZqElFDWoJRba//NR2LkUGnReQMVCu2fGdHFbNTSAA=; b=tT5+arST16B6LHAsu0nvdMGz8kOMUAV4AsDsBOsOCxrFA0ECcyBFEuYK53g6VD42zn O8J/2vwSN27eBWSIKENs3zn4QTRq8rO7yJ6yG/2B6C6dJ5wj8W5TJ9sjpvWMT6znTCAF uBoaCrTai0TL8cSDY6Ulg3LkVxVZeVlmMsX8cQfnukWGMAM5EPvRg+A/gkaBEDkz3NfS HTXW9FwxCne1phNKGqQ068gdNJoVy6/8AwN9U4d703/cPXrMefPP33OHmcsP4SId9Bnc jnS9E0D2y5rMF0A5ySf2gHqPWUOGd4EF27+pTblUQh21BhJZNFK8U3JvKj047xVRmEzv wcYw== X-Gm-Message-State: AOAM5310E3e0Vt12gHkjcdHd11csTKIDktu2f4iCFexFOifwtJpVr42y AiDkHybIDLlN7sLWEowRIYM= X-Google-Smtp-Source: ABdhPJz13ephTgXqUM+UA4TNO69iRYovunNJ91G6lEVq9z9+l6sFos6sysWM6KLFb8PBzO0QEnt7Cw== X-Received: by 2002:a63:48c:: with SMTP id 134mr9440077pge.122.1627850001180; Sun, 01 Aug 2021 13:33:21 -0700 (PDT) Received: from localhost.localdomain ([2402:3a80:15b3:589:f07d:5386:a3c2:3056]) by smtp.gmail.com with ESMTPSA id k10sm8897974pfc.169.2021.08.01.13.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Aug 2021 13:33:20 -0700 (PDT) From: Himadri Pandya To: johan@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Himadri Pandya Subject: [PATCH v2 6/6] USB: serial: kl5kusb105: use usb_control_msg_recv() and usb_control_msg_send() Date: Mon, 2 Aug 2021 02:01:22 +0530 Message-Id: <20210801203122.3515-7-himadrispandya@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210801203122.3515-1-himadrispandya@gmail.com> References: <20210801203122.3515-1-himadrispandya@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The wrappers usb_control_msg_send/recv eliminate the need of allocating dma buffers for usb message. They also impose proper error checks on the return value of usb_control_msg() to handle short read/write. Hence use the wrappers and remove dma allocations. Signed-off-by: Himadri Pandya --- Changes in v2: - Fix the caller of klsi_105_chg_port_settings() - Drop unnecessary use of the wrappers --- drivers/usb/serial/kl5kusb105.c | 79 ++++++++++++++------------------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index f1e9628a9907..72d3920c9c48 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c @@ -124,16 +124,18 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port, { int rc; - rc = usb_control_msg(port->serial->dev, - usb_sndctrlpipe(port->serial->dev, 0), - KL5KUSB105A_SIO_SET_DATA, - USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE, - 0, /* value */ - 0, /* index */ - settings, - sizeof(struct klsi_105_port_settings), - KLSI_TIMEOUT); - if (rc < 0) + rc = usb_control_msg_send(port->serial->dev, + 0, + KL5KUSB105A_SIO_SET_DATA, + USB_TYPE_VENDOR | USB_DIR_OUT | + USB_RECIP_INTERFACE, + 0, /* value */ + 0, /* index */ + settings, + sizeof(struct klsi_105_port_settings), + KLSI_TIMEOUT, + GFP_KERNEL); + if (rc) dev_err(&port->dev, "Change port settings failed (error = %d)\n", rc); @@ -167,28 +169,21 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, unsigned long *line_state_p) { int rc; - u8 *status_buf; + u8 status_buf[KLSI_STATUSBUF_LEN]; __u16 status; - status_buf = kmalloc(KLSI_STATUSBUF_LEN, GFP_KERNEL); - if (!status_buf) - return -ENOMEM; - status_buf[0] = 0xff; status_buf[1] = 0xff; - rc = usb_control_msg(port->serial->dev, - usb_rcvctrlpipe(port->serial->dev, 0), - KL5KUSB105A_SIO_POLL, - USB_TYPE_VENDOR | USB_DIR_IN, - 0, /* value */ - 0, /* index */ - status_buf, KLSI_STATUSBUF_LEN, - 10000 - ); - if (rc != KLSI_STATUSBUF_LEN) { + 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, + 10000, + GFP_KERNEL); + if (rc) { dev_err(&port->dev, "reading line status failed: %d\n", rc); - if (rc >= 0) - rc = -EIO; } else { status = get_unaligned_le16(status_buf); @@ -198,7 +193,6 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, *line_state_p = klsi_105_status2linestate(status); } - kfree(status_buf); return rc; } @@ -245,7 +239,7 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port) int retval = 0; int rc; unsigned long line_state; - struct klsi_105_port_settings *cfg; + struct klsi_105_port_settings cfg; unsigned long flags; /* Do a defined restart: @@ -255,27 +249,22 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port) * Then read the modem line control and store values in * priv->line_state. */ - cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); - if (!cfg) - return -ENOMEM; - cfg->pktlen = 5; - cfg->baudrate = kl5kusb105a_sio_b9600; - cfg->databits = kl5kusb105a_dtb_8; - cfg->unknown1 = 0; - cfg->unknown2 = 1; - klsi_105_chg_port_settings(port, cfg); + cfg.pktlen = 5; + cfg.baudrate = kl5kusb105a_sio_b9600; + cfg.databits = kl5kusb105a_dtb_8; + cfg.unknown1 = 0; + cfg.unknown2 = 1; + klsi_105_chg_port_settings(port, &cfg); spin_lock_irqsave(&priv->lock, flags); - priv->cfg.pktlen = cfg->pktlen; - priv->cfg.baudrate = cfg->baudrate; - priv->cfg.databits = cfg->databits; - priv->cfg.unknown1 = cfg->unknown1; - priv->cfg.unknown2 = cfg->unknown2; + priv->cfg.pktlen = cfg.pktlen; + priv->cfg.baudrate = cfg.baudrate; + priv->cfg.databits = cfg.databits; + priv->cfg.unknown1 = cfg.unknown1; + priv->cfg.unknown2 = cfg.unknown2; spin_unlock_irqrestore(&priv->lock, flags); - kfree(cfg); - /* READ_ON and urb submission */ rc = usb_serial_generic_open(tty, port); if (rc)