From patchwork Wed Sep 23 09:05:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himadri Pandya X-Patchwork-Id: 258450 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 72B23C2D0A8 for ; Wed, 23 Sep 2020 09:06:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20C2C20838 for ; Wed, 23 Sep 2020 09:06:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dISF/+v1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbgIWJGZ (ORCPT ); Wed, 23 Sep 2020 05:06:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726178AbgIWJGZ (ORCPT ); Wed, 23 Sep 2020 05:06:25 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 924E5C0613CE; Wed, 23 Sep 2020 02:06:25 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id o20so14635135pfp.11; Wed, 23 Sep 2020 02:06:25 -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=9wqyDxCNM1ZmfXa7nbXb7Mn0Y5gUAzSUKtchYYWUpJU=; b=dISF/+v1MKuq0CK2motDdh3V2whOwEUQ0JQa9nsULg7BgNFuOPOPMev3ItuaoT6cyr 18ahUyW73hY7lapUSnFqh6NOYsMuKbkZD1MdUOHCa4uRofa/fH1CtoQC9tQlZnonvfOB WcBRQK4uSS/5hj76YHa03/UiGig/VrVOWFXlj7MJnml8TzkSF2qbgcPvjxUzV/qCNKir fmTucJV/ocmQkG3ZzjFmjP0T/a+Aku9HRlPiw4hlDRRsRBAlDAw11KPIe9nApFpl4dZu H1Z+EdbICMo9FNe70JlKq0iq4g8PFVFSBugHYGWewVMvTTK8lGYxnQXQ18H6K4gARDWK u/0Q== 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=9wqyDxCNM1ZmfXa7nbXb7Mn0Y5gUAzSUKtchYYWUpJU=; b=MGiv8ZdsbcQ1MMDmxFlAiejE1Y0NZJIM6iHW99S8UdL5jWNeaMf9GlnlAGLbCmjXXF Balrf+FnNOcO3ez9MXi9YT7gdIHb49NijDLNQon557z6JZVOefJQZBp4x+/7FkO/ZBpT JLJeGHAw6V6umkKVPbFfVirNXFzf44DWWv30JhmMy9JJvuJw0gA1rZGHVJBqln1DnyOC 1n5Y9unnjBAblsEZjReW38orE5LWfk7OXrzipGDVin+SueRBLcvcBUOuhOIN6obcjt3P aCmjJIvQvsko+9hQlKFOwCTIm2/ucR869iim3FeOFyHsYObt4kREw2MExFJZ3hEuZKIp hUyw== X-Gm-Message-State: AOAM531UXXvA7c9/ZiOlufKtY34tVO/8MfNAQFmyzwEk83wJSUo93pzh edIvz5bs9m9ODa4Aj4oNp8laEfHw7X1Dfw== X-Google-Smtp-Source: ABdhPJxaQQZDbcNj1V/nmPJgyNv/1vOPTcJ94kyuQKAHILMIKBY+cdozA5yX3z9UKcfNL8ZFpPuX2Q== X-Received: by 2002:a63:a548:: with SMTP id r8mr6914557pgu.256.1600851985200; Wed, 23 Sep 2020 02:06:25 -0700 (PDT) Received: from localhost.localdomain ([2405:205:c8e3:4b96:985a:95b9:e0cd:1d5e]) by smtp.gmail.com with ESMTPSA id a13sm16496226pgq.41.2020.09.23.02.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2020 02:06:24 -0700 (PDT) From: Himadri Pandya To: davem@davemloft.net, kuba@kernel.org, oneukum@suse.com, pankaj.laxminarayan.bharadiya@intel.com, keescook@chromium.org, yuehaibing@huawei.com, petkan@nucleusys.com, ogiannou@gmail.com Cc: linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, gregkh@linuxfoundation.org, Himadri Pandya Subject: [PATCH 1/4] net: usbnet: use usb_control_msg_recv() and usb_control_msg_send() Date: Wed, 23 Sep 2020 14:35:16 +0530 Message-Id: <20200923090519.361-2-himadrispandya@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200923090519.361-1-himadrispandya@gmail.com> References: <20200923090519.361-1-himadrispandya@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Potential incorrect use of usb_control_msg() has resulted in new wrapper functions to enforce its correct usage with proper error check. Hence use these new wrapper functions instead of calling usb_control_msg() directly. Signed-off-by: Himadri Pandya --- drivers/net/usb/usbnet.c | 46 ++++------------------------------------ 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index 2b2a841cd938..a38a85bef46a 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -1982,64 +1982,26 @@ EXPORT_SYMBOL(usbnet_link_change); static int __usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, u16 value, u16 index, void *data, u16 size) { - void *buf = NULL; - int err = -ENOMEM; - netdev_dbg(dev->net, "usbnet_read_cmd cmd=0x%02x reqtype=%02x" " value=0x%04x index=0x%04x size=%d\n", cmd, reqtype, value, index, size); - if (size) { - buf = kmalloc(size, GFP_KERNEL); - if (!buf) - goto out; - } - - err = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), - cmd, reqtype, value, index, buf, size, + return usb_control_msg_recv(dev->udev, 0, + cmd, reqtype, value, index, data, size, USB_CTRL_GET_TIMEOUT); - if (err > 0 && err <= size) { - if (data) - memcpy(data, buf, err); - else - netdev_dbg(dev->net, - "Huh? Data requested but thrown away.\n"); - } - kfree(buf); -out: - return err; } static int __usbnet_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, u16 value, u16 index, const void *data, u16 size) { - void *buf = NULL; - int err = -ENOMEM; - netdev_dbg(dev->net, "usbnet_write_cmd cmd=0x%02x reqtype=%02x" " value=0x%04x index=0x%04x size=%d\n", cmd, reqtype, value, index, size); - if (data) { - buf = kmemdup(data, size, GFP_KERNEL); - if (!buf) - goto out; - } else { - if (size) { - WARN_ON_ONCE(1); - err = -EINVAL; - goto out; - } - } - - err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), - cmd, reqtype, value, index, buf, size, + return usb_control_msg_send(dev->udev, 0, + cmd, reqtype, value, index, data, size, USB_CTRL_SET_TIMEOUT); - kfree(buf); - -out: - return err; } /* From patchwork Wed Sep 23 09:05:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himadri Pandya X-Patchwork-Id: 297540 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 21B4AC4727D for ; Wed, 23 Sep 2020 09:06:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAAF0214D8 for ; Wed, 23 Sep 2020 09:06:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MN7prrBh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726574AbgIWJGg (ORCPT ); Wed, 23 Sep 2020 05:06:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726178AbgIWJGg (ORCPT ); Wed, 23 Sep 2020 05:06:36 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F514C0613CE; Wed, 23 Sep 2020 02:06:36 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id u4so781346plr.4; Wed, 23 Sep 2020 02:06:36 -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=4hMw1RpDG2ueDcMztQfcOaK5AOnLojLAqwfMF9XGROw=; b=MN7prrBhdAPs9exEUsWKusuKzl+zDaoVHcta4SOezeQVnnRK5JTMfxKgvIRUrfqlX1 JxxNYW8aKO7LGB3q24iqWgnrCuatOU5YRcc6Q2jSee48qbDjTJiJ0o5sngLHOyXQJC1H Cbqo9NTVpBOOmOmJHvCR4b1bxBYGTHFHET3VyrHj29oOVO+6sHKRCAdlZfzbFHByduhq VFBgRY7th3zbBn/cbsRKwvjQDkcpHC3814F2BQ6Zi9ET8dx8ImzcO7qykgSJqJQ2E6X4 XyvCPI1SxjoPQggMxxlUh+a462MlD8gFNWEpwb7U1TXPENOcWl40BPj7GEIZYSJ+6cc6 Rseg== 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=4hMw1RpDG2ueDcMztQfcOaK5AOnLojLAqwfMF9XGROw=; b=aXvUXeUJB8a4EVaWj+R+jd1ed6hVoZ0ZRI9buxvxjG+cLD6ionZ689wQfhmIwzCPsh XyYV/OpB8Bi8G0AqBpOzVpsIA2LlDBp5fegdA0Rnhe6mMNrfHAIUOIkG/ckgP4kYdHgX 3YOGrfSQ0jtzpQHOXSfUgjR6GnhYn4Tg5GxDNTjuYCnctVogq4/v1OsjO4xSxdSoRVTI RP/yrQMqdTc4mxNSQuYaN04MDBbG8d5ibqbtkpN6nh7gPTz8sQ/Z20zp0NcpcrTY8zog lC0ZGtKhg+iDRlSlbtw46HE5ubOwny77p22W1Z0BZUfSsPq+2b4QxLM1T/xWwO22lbmF o+8w== X-Gm-Message-State: AOAM5337UGrVtu765ViVK0B0BYYSzR3EYmVK1FF5Qn317OHNhE4JU+ta h9QuS3vqQYXUL3HzpF/NaYQ= X-Google-Smtp-Source: ABdhPJzxcZopb1qURZ4Ezng98Hm8eG9OwKY8RKzypvJ2LdSnc67p6QCdccsb2i+2hqermlODln9MnQ== X-Received: by 2002:a17:902:ab87:b029:d2:1ceb:34 with SMTP id f7-20020a170902ab87b02900d21ceb0034mr8728665plr.12.1600851995638; Wed, 23 Sep 2020 02:06:35 -0700 (PDT) Received: from localhost.localdomain ([2405:205:c8e3:4b96:985a:95b9:e0cd:1d5e]) by smtp.gmail.com with ESMTPSA id a13sm16496226pgq.41.2020.09.23.02.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2020 02:06:35 -0700 (PDT) From: Himadri Pandya To: davem@davemloft.net, kuba@kernel.org, oneukum@suse.com, pankaj.laxminarayan.bharadiya@intel.com, keescook@chromium.org, yuehaibing@huawei.com, petkan@nucleusys.com, ogiannou@gmail.com Cc: linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, gregkh@linuxfoundation.org, Himadri Pandya Subject: [PATCH 2/4] net: sierra_net: use usb_control_msg_recv() Date: Wed, 23 Sep 2020 14:35:17 +0530 Message-Id: <20200923090519.361-3-himadrispandya@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200923090519.361-1-himadrispandya@gmail.com> References: <20200923090519.361-1-himadrispandya@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The new usb api function usb_control_msg_recv() nicely wrapps usb_control_msg() with proper error check. Hence use it instead of directly calling usb_control_msg(). Signed-off-by: Himadri Pandya --- drivers/net/usb/sierra_net.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c index 0abd257b634c..f3a5f83cb256 100644 --- a/drivers/net/usb/sierra_net.c +++ b/drivers/net/usb/sierra_net.c @@ -478,16 +478,13 @@ static void sierra_net_kevent(struct work_struct *work) return; ifnum = priv->ifnum; - len = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), - USB_CDC_GET_ENCAPSULATED_RESPONSE, - USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE, - 0, ifnum, buf, SIERRA_NET_USBCTL_BUF_LEN, - USB_CTRL_SET_TIMEOUT); - - if (len < 0) { - netdev_err(dev->net, - "usb_control_msg failed, status %d\n", len); - } else { + len = usb_control_msg_recv(dev->udev, usb_rcvctrlpipe(dev->udev, 0), + USB_CDC_GET_ENCAPSULATED_RESPONSE, + USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, + 0, ifnum, buf, SIERRA_NET_USBCTL_BUF_LEN, + USB_CTRL_SET_TIMEOUT); + + if (len) { struct hip_hdr hh; dev_dbg(&dev->udev->dev, "%s: Received status message," From patchwork Wed Sep 23 09:05:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himadri Pandya X-Patchwork-Id: 258449 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 018F2C2D0A8 for ; Wed, 23 Sep 2020 09:06:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B135F214D8 for ; Wed, 23 Sep 2020 09:06:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t45qHV5x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726638AbgIWJGp (ORCPT ); Wed, 23 Sep 2020 05:06:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726178AbgIWJGp (ORCPT ); Wed, 23 Sep 2020 05:06:45 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94FF9C0613CE; Wed, 23 Sep 2020 02:06:45 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id kk9so2835589pjb.2; Wed, 23 Sep 2020 02:06:45 -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=ohqofdSobCRCHUofKcLY6g/yoMPZMTZlQOhkO7ROpIc=; b=t45qHV5xy9oCsiCxleGrHt9GVIvdSr7r/29ELFE6fyyIECqNBASF2IXz4aPPAoDY5K K+p3/cSNcE6Ww4N/oMMXunz5zmcBJMYvhX/qM1RMr2x7AM0HOHFNMj6azREPcp43F/Kl pPprwzv1qQWoDeBNz/Ul9ZzeDRQqzuxtTU8eBsB9AS6CPCyLQKdL0aaPV5QsFpBbCTgR 2hd1YWTeOo9lOaUcdgo6KfzXKCRR5QtNacpdldsFCbU7dBdboewwGqo/oAwfQYc5Z4kf n8IQkOXkhXrANnzYIxbN4jp9x+At41CD7vWYCO/UfSr2d5SENYvOM8tyJsvivjPTn4+z o0dg== 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=ohqofdSobCRCHUofKcLY6g/yoMPZMTZlQOhkO7ROpIc=; b=rij+feCqg/x60OoaE/MsMoUYNlD6RoPyWyH29orsxZzDc0ThFX6H/drsGIuZzKTXsF 3bFdHSYjndHOAdSHyF/M/W+7xMq9byte1XqHNhv0IriRxchJcCAxBqeyKfARLdbELKR+ R66RY0Y+c7ZPaPpTLejv2yRE3VdL/+JfKAWnMAUyu56N+XqbAQlAtAFe9Z/TH4bTHOvn tjjt+J2aWhrzfHn4cHdxwpcSquhIHA1XUOKeci0fbUMPP7gB50jObE3X7HaatmvyvLu/ ZR6RvWzsD+6DuMFHuuJr2/gz3YewWy6dzS39VMcGXEfdgUQVaeFN7T+LNNtoQ4t+LlxO fl6w== X-Gm-Message-State: AOAM532mgoiJtgGiSZdL79uskfsuoVFWDiaGPfbov8NZ1nOatRGnpnKm 3nkSk+/p0JXE4luQLu/+UZE= X-Google-Smtp-Source: ABdhPJxWZjsJJUAi8SjYqaGIPZnjo6hVFfFI7ws+vWAwRi4JJbhwh0TRZ8zwgoZCawVZ511ar062WA== X-Received: by 2002:a17:90a:9f09:: with SMTP id n9mr7403612pjp.88.1600852004228; Wed, 23 Sep 2020 02:06:44 -0700 (PDT) Received: from localhost.localdomain ([2405:205:c8e3:4b96:985a:95b9:e0cd:1d5e]) by smtp.gmail.com with ESMTPSA id a13sm16496226pgq.41.2020.09.23.02.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2020 02:06:43 -0700 (PDT) From: Himadri Pandya To: davem@davemloft.net, kuba@kernel.org, oneukum@suse.com, pankaj.laxminarayan.bharadiya@intel.com, keescook@chromium.org, yuehaibing@huawei.com, petkan@nucleusys.com, ogiannou@gmail.com Cc: linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, gregkh@linuxfoundation.org, Himadri Pandya Subject: [PATCH 3/4] net: usb: rtl8150: use usb_control_msg_recv() and usb_control_msg_send() Date: Wed, 23 Sep 2020 14:35:18 +0530 Message-Id: <20200923090519.361-4-himadrispandya@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200923090519.361-1-himadrispandya@gmail.com> References: <20200923090519.361-1-himadrispandya@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Many usage of usb_control_msg() do not have proper error check on return value leaving scope for bugs on short reads. New usb_control_msg_recv() and usb_control_msg_send() nicely wraps usb_control_msg() with proper error check. Hence use the wrappers instead of calling usb_control_msg() directly. Signed-off-by: Himadri Pandya --- drivers/net/usb/rtl8150.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c index 733f120c852b..e3002b675921 100644 --- a/drivers/net/usb/rtl8150.c +++ b/drivers/net/usb/rtl8150.c @@ -152,36 +152,16 @@ static const char driver_name [] = "rtl8150"; */ static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data) { - void *buf; - int ret; - - buf = kmalloc(size, GFP_NOIO); - if (!buf) - return -ENOMEM; - - ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), - RTL8150_REQ_GET_REGS, RTL8150_REQT_READ, - indx, 0, buf, size, 500); - if (ret > 0 && ret <= size) - memcpy(data, buf, ret); - kfree(buf); - return ret; + return usb_control_msg_recv(dev->udev, 0, RTL8150_REQ_GET_REGS, + RTL8150_REQT_READ, indx, 0, data, + size, 500); } static int set_registers(rtl8150_t * dev, u16 indx, u16 size, const void *data) { - void *buf; - int ret; - - buf = kmemdup(data, size, GFP_NOIO); - if (!buf) - return -ENOMEM; - - ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), - RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE, - indx, 0, buf, size, 500); - kfree(buf); - return ret; + return usb_control_msg_send(dev->udev, 0, RTL8150_REQ_SET_REGS, + RTL8150_REQT_WRITE, indx, 0, data, + size, 500); } static void async_set_reg_cb(struct urb *urb) From patchwork Wed Sep 23 09:05:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himadri Pandya X-Patchwork-Id: 297539 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=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 645FFC2D0A8 for ; Wed, 23 Sep 2020 09:07:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2707D214D8 for ; Wed, 23 Sep 2020 09:07:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MgLNdF2R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726676AbgIWJGz (ORCPT ); Wed, 23 Sep 2020 05:06:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726178AbgIWJGz (ORCPT ); Wed, 23 Sep 2020 05:06:55 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BD74C0613CE; Wed, 23 Sep 2020 02:06:55 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id z18so14666709pfg.0; Wed, 23 Sep 2020 02:06:55 -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=nCiWWFhPZHev6oEz8DjlpYK4lz9H8pn9x46uJm2Olsw=; b=MgLNdF2RgGy0Y7v89R1UC4S84n8EAycuEswaYSu7ys11XIGLnCTwJkdYnef+/EWOhd /+GVeEf22uDINRfdERiHGMYB1K9cob+LGc7P5L2mQ3vHYhBjGvxdCraFqL3QsVgaEX5Y GjM/RB9A/3VKzbT5O6Sk9mzQq7dRUggoiR+xaoNEtnSjftBJT7pJno+pzW6U5jQ5zSK3 ufXxacUn3fLp7LtuiCdsO4MgpKX9DUXdwRgWf5UNwYs61XY+vmV5fmOlLWRoTTV/oHkQ pquXNlQstKZrAOQDbrDmbPtHBf7nU2JeM0cPG30QxBNWIOnK5MkXq7lqHQ8WB/V9ajc1 wpbQ== 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=nCiWWFhPZHev6oEz8DjlpYK4lz9H8pn9x46uJm2Olsw=; b=EGczJgYdpt3p0OSfVn0QSPFZiMm97dpJcic9SDuE4nlG2NTyPNrao/0VxZFzBrSw4T iNQmWlI7/Q4YCmg4IhbvUWKnwv+g0++w0rGbnKl8nP0mUBQiUD0Q3eKT0lYN8eDyE0Jm 0zeykyFDYmN+6uy+YT4xF9YXTZc4kgSli2tvYugTW4ZgkjVFsV2lXmoIBCu2rA/O9OOO lwBTUx5Z2IZ7j69Z+7zGDpzx2+oKzb30JtThE2E/ZEDFuTxH2FvhcBlVpCbkPncqVTpL 0HF8iaYgD1FrqGByetp9AJm2kpfLQxs/PF/11yuU8wRrUb71JCot6J0/J4fAyWJZ71g1 uBRw== X-Gm-Message-State: AOAM530Q4I8ruBdRv7PNHR8WsVJNK6cOLlpvmPh9OfBJNUqEnbl1nj8O KHhdd+NnxB4ogb7vmL2srAY= X-Google-Smtp-Source: ABdhPJyhgq8hJykGKP8WPG3DhPxvF42QE1aH6zDRXCfxkxSWkDChBSkLj4Om8/Pg4+SRnSpW7WE1CQ== X-Received: by 2002:a62:e90b:0:b029:13e:b622:3241 with SMTP id j11-20020a62e90b0000b029013eb6223241mr7946741pfh.12.1600852014989; Wed, 23 Sep 2020 02:06:54 -0700 (PDT) Received: from localhost.localdomain ([2405:205:c8e3:4b96:985a:95b9:e0cd:1d5e]) by smtp.gmail.com with ESMTPSA id a13sm16496226pgq.41.2020.09.23.02.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2020 02:06:54 -0700 (PDT) From: Himadri Pandya To: davem@davemloft.net, kuba@kernel.org, oneukum@suse.com, pankaj.laxminarayan.bharadiya@intel.com, keescook@chromium.org, yuehaibing@huawei.com, petkan@nucleusys.com, ogiannou@gmail.com Cc: linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, gregkh@linuxfoundation.org, Himadri Pandya Subject: [PATCH 4/4] net: rndis_host: use usb_control_msg_recv() and usb_control_msg_send() Date: Wed, 23 Sep 2020 14:35:19 +0530 Message-Id: <20200923090519.361-5-himadrispandya@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200923090519.361-1-himadrispandya@gmail.com> References: <20200923090519.361-1-himadrispandya@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The new usb_control_msg_recv() and usb_control_msg_send() nicely wraps usb_control_msg() with proper error check. Hence use the wrappers instead of calling usb_control_msg() directly. Signed-off-by: Himadri Pandya --- drivers/net/usb/rndis_host.c | 44 ++++++++++++++---------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c index 6fa7a009a24a..30fc4a7183d3 100644 --- a/drivers/net/usb/rndis_host.c +++ b/drivers/net/usb/rndis_host.c @@ -113,14 +113,13 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) buf->request_id = (__force __le32) xid; } master_ifnum = info->control->cur_altsetting->desc.bInterfaceNumber; - retval = usb_control_msg(dev->udev, - usb_sndctrlpipe(dev->udev, 0), - USB_CDC_SEND_ENCAPSULATED_COMMAND, - USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0, master_ifnum, - buf, le32_to_cpu(buf->msg_len), - RNDIS_CONTROL_TIMEOUT_MS); - if (unlikely(retval < 0 || xid == 0)) + retval = usb_control_msg_send(dev->udev, 0, + USB_CDC_SEND_ENCAPSULATED_COMMAND, + USB_TYPE_CLASS | USB_RECIP_INTERFACE, + 0, master_ifnum, buf, + le32_to_cpu(buf->msg_len), + RNDIS_CONTROL_TIMEOUT_MS); + if (unlikely(xid == 0)) return retval; /* Some devices don't respond on the control channel until @@ -139,14 +138,11 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) /* Poll the control channel; the request probably completed immediately */ rsp = le32_to_cpu(buf->msg_type) | RNDIS_MSG_COMPLETION; for (count = 0; count < 10; count++) { - memset(buf, 0, CONTROL_BUFFER_SIZE); - retval = usb_control_msg(dev->udev, - usb_rcvctrlpipe(dev->udev, 0), - USB_CDC_GET_ENCAPSULATED_RESPONSE, - USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0, master_ifnum, - buf, buflen, - RNDIS_CONTROL_TIMEOUT_MS); + retval = usb_control_msg_recv(dev->udev, 0, + USB_CDC_GET_ENCAPSULATED_RESPONSE, + USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, + 0, master_ifnum, buf, buflen, + RNDIS_CONTROL_TIMEOUT_MS); if (likely(retval >= 8)) { msg_type = le32_to_cpu(buf->msg_type); msg_len = le32_to_cpu(buf->msg_len); @@ -178,17 +174,11 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) msg->msg_type = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C); msg->msg_len = cpu_to_le32(sizeof *msg); msg->status = cpu_to_le32(RNDIS_STATUS_SUCCESS); - retval = usb_control_msg(dev->udev, - usb_sndctrlpipe(dev->udev, 0), - USB_CDC_SEND_ENCAPSULATED_COMMAND, - USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0, master_ifnum, - msg, sizeof *msg, - RNDIS_CONTROL_TIMEOUT_MS); - if (unlikely(retval < 0)) - dev_dbg(&info->control->dev, - "rndis keepalive err %d\n", - retval); + retval = usb_control_msg_send(dev->udev, 0, + USB_CDC_SEND_ENCAPSULATED_COMMAND, + USB_TYPE_CLASS | USB_RECIP_INTERFACE, + 0, master_ifnum, msg, sizeof(*msg), + RNDIS_CONTROL_TIMEOUT_MS); } break; default: