From patchwork Sun Sep 27 12:49:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petko Manolov X-Patchwork-Id: 11802093 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B30B6CB for ; Sun, 27 Sep 2020 12:49:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 801C12389F for ; Sun, 27 Sep 2020 12:49:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=konsulko.com header.i=@konsulko.com header.b="XaFqJ0uD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726610AbgI0MtV (ORCPT ); Sun, 27 Sep 2020 08:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgI0MtT (ORCPT ); Sun, 27 Sep 2020 08:49:19 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E980EC0613CE for ; Sun, 27 Sep 2020 05:49:18 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id a12so7061307eds.13 for ; Sun, 27 Sep 2020 05:49:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NDPhIefhnly1S9Y7P2oJIAz1qGyr+mMVBvietpnTvjY=; b=XaFqJ0uDXzuLvoDhbzvyGlkRvF3+6HO5NNFE0oUCCRI0LtApsCkv/Zo/Ed537nAiWy FQuKoKIy/unl7JjgucNkY/hTWb8VQFiZ5CqOJxlnVj2taNY//3/zj65sQZMdnGeGKfAd 2eUrFZoOxOj6D5dDFuOkQxSXp02ymtEi1Ft7A= 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:mime-version:content-transfer-encoding; bh=NDPhIefhnly1S9Y7P2oJIAz1qGyr+mMVBvietpnTvjY=; b=pFzi1Jh0Th+3l8em+hMwFFPma1Kw17476csDvOpSEx63dhMUGu2u9lA/KtlI0lgQhA OV633i7noBtmcGsj+ZL1fKcC415Nc22mDUQTtHY1BLGXv+BaKB/tn2+dqC0eFV7rJWIm EI/E89thWYhmWgmYTdqv+jrMkt7ek/UcUOJ6x2sQaMqSJTJPRol1RjFzYu6W5OxJuABL +XfZFIHS69W9FlYp3jUhI1I61JO9MfudshxSpd5DXgHaAP9qwBvllu6BYieL+BuyjeIp xhlIvIE5EZeZB4uUGrHaV4yOBaySxG/ZyUEJzrE+4nK4morg9JgP2Ap3891Gt7ZcKOSM II4Q== X-Gm-Message-State: AOAM532Ex3+dY35Lg4jQiquhsYiss57vbE0NrO5E1EMLgET2D5Q+oljT CJgAG+/3/LsZbOhjSs5nxZPcsQ== X-Google-Smtp-Source: ABdhPJzN4OEV8wFxmWfiCB2uJNGsbgKpyAK69Ammi4HhIZ5mk/5pxYkHqhpGV/DxbmYgM+C3zM71IA== X-Received: by 2002:aa7:d593:: with SMTP id r19mr11126017edq.331.1601210957574; Sun, 27 Sep 2020 05:49:17 -0700 (PDT) Received: from taos.konsulko.bg (lan.nucleusys.com. [92.247.61.126]) by smtp.gmail.com with ESMTPSA id r16sm7234275edc.57.2020.09.27.05.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 05:49:17 -0700 (PDT) From: Petko Manolov To: gregKH@linuxfoundation.org Cc: linux-usb@vger.kernel.org, davem@davemloft.net, netdev@vger.kernel.org, Petko Manolov Subject: [PATCH RESEND v3 1/2] net: pegasus: Use the new usb control message API. Date: Sun, 27 Sep 2020 15:49:08 +0300 Message-Id: <20200927124909.16380-2-petko.manolov@konsulko.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200927124909.16380-1-petko.manolov@konsulko.com> References: <20200923134348.23862-9-oneukum@suse.com> <20200927124909.16380-1-petko.manolov@konsulko.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The old usb_control_msg() let the caller handle the error and also did not account for partial reads. Since these are now considered harmful, move the driver over to usb_control_msg_recv/send() calls. Added small note about why set_registers() can't be used to substitute set_register(). Signed-off-by: Petko Manolov --- drivers/net/usb/pegasus.c | 61 ++++++++++----------------------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c index e92cb51a2c77..26b4e48bf91f 100644 --- a/drivers/net/usb/pegasus.c +++ b/drivers/net/usb/pegasus.c @@ -124,62 +124,31 @@ static void async_ctrl_callback(struct urb *urb) static int get_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data) { - u8 *buf; - int ret; - - buf = kmalloc(size, GFP_NOIO); - if (!buf) - return -ENOMEM; - - ret = usb_control_msg(pegasus->usb, usb_rcvctrlpipe(pegasus->usb, 0), - PEGASUS_REQ_GET_REGS, PEGASUS_REQT_READ, 0, - indx, buf, size, 1000); - if (ret < 0) - netif_dbg(pegasus, drv, pegasus->net, - "%s returned %d\n", __func__, ret); - else if (ret <= size) - memcpy(data, buf, ret); - kfree(buf); - return ret; + return usb_control_msg_recv(pegasus->usb, 0, PEGASUS_REQ_GET_REGS, + PEGASUS_REQT_READ, 0, indx, data, size, + 1000, GFP_NOIO); } static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size, const void *data) { - u8 *buf; - int ret; - - buf = kmemdup(data, size, GFP_NOIO); - if (!buf) - return -ENOMEM; - - ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), - PEGASUS_REQ_SET_REGS, PEGASUS_REQT_WRITE, 0, - indx, buf, size, 100); - if (ret < 0) - netif_dbg(pegasus, drv, pegasus->net, - "%s returned %d\n", __func__, ret); - kfree(buf); - return ret; + return usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REGS, + PEGASUS_REQT_WRITE, 0, indx, data, size, + 1000, GFP_NOIO); } +/* + * There is only one way to write to a single ADM8511 register and this is via + * specific control request. 'data' is ignored by the device, but it is here to + * not break the API. + */ static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data) { - u8 *buf; - int ret; - - buf = kmemdup(&data, 1, GFP_NOIO); - if (!buf) - return -ENOMEM; + void *buf = &data; - ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), - PEGASUS_REQ_SET_REG, PEGASUS_REQT_WRITE, data, - indx, buf, 1, 1000); - if (ret < 0) - netif_dbg(pegasus, drv, pegasus->net, - "%s returned %d\n", __func__, ret); - kfree(buf); - return ret; + return usb_control_msg_send(pegasus->usb, 0, PEGASUS_REQ_SET_REG, + PEGASUS_REQT_WRITE, data, indx, buf, 1, + 1000, GFP_NOIO); } static int update_eth_regs_async(pegasus_t *pegasus) From patchwork Sun Sep 27 12:49:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petko Manolov X-Patchwork-Id: 11802097 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11A896CB for ; Sun, 27 Sep 2020 12:49:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBCAC23976 for ; Sun, 27 Sep 2020 12:49:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=konsulko.com header.i=@konsulko.com header.b="YSpL+toI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726617AbgI0MtW (ORCPT ); Sun, 27 Sep 2020 08:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726604AbgI0MtU (ORCPT ); Sun, 27 Sep 2020 08:49:20 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C14CC0613D5 for ; Sun, 27 Sep 2020 05:49:20 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id b12so7075035edz.11 for ; Sun, 27 Sep 2020 05:49:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2lSGROVpoGDqKpQV7Vk31ZIPu0grmXKx5AXVK7t2aWA=; b=YSpL+toI4XwAP28Dttrl4q1k50ljTdnyLNBAwqDbE+imYCHhfDXj4o6jp33Yb8CxVU QSNRPOrNf3Wnk3CmXc3NmT187UW0E0fRQTRkc30lWPz6ZHTEbZx+aUeZByJcig66B9NE Uk28IerZkYoqLZBOt/tFpPJNTI48oSxgfP60U= 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:mime-version:content-transfer-encoding; bh=2lSGROVpoGDqKpQV7Vk31ZIPu0grmXKx5AXVK7t2aWA=; b=iLQxAcBkR0CQG7FhqKI/mVfTP2qbJbj8i5tItikbgqvdb6nbGaQxh6aqPGbduU4tBH tUf9pBj0d8a0ynA51KZCfm6ufoljlIC+EhcH9IIeRh0ujXfN13KMLEk+yKmuSmDguzA2 hixTdz1gZ66lcEJQUZFrbmudh4kdTcXF5X1vfST13+uUtHKgQnsjNtJVlkGtZ/br65u9 YiRj04FDc9ChC/b+72rhClfe7vpJEoaQLV9Mj5rysc+QUTQdAUyld2JirsLemXKkv/MV J5azMndaXzjhhmm1u8fcgjhBhlMPQ7oOF2irXVXqR7zCrsjl3N0IN3aDlfv7dz628b7t q27A== X-Gm-Message-State: AOAM5332MgSQVWxLoTmbu9RvZ4VqZ+2HEJwsvPr3ICALgFVPJw//dUA/ WmWZkkxZcdGcsQnxktqZbOTodQ== X-Google-Smtp-Source: ABdhPJyxSaPGOBqQxH+Y/pTxrZfw1o2rmXjFy/PmXOqAuZT/2U3pYMsQlhZMvCMaW6Wxka5ynvPZ8Q== X-Received: by 2002:a05:6402:50f:: with SMTP id m15mr11280382edv.41.1601210958742; Sun, 27 Sep 2020 05:49:18 -0700 (PDT) Received: from taos.konsulko.bg (lan.nucleusys.com. [92.247.61.126]) by smtp.gmail.com with ESMTPSA id r16sm7234275edc.57.2020.09.27.05.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 05:49:18 -0700 (PDT) From: Petko Manolov To: gregKH@linuxfoundation.org Cc: linux-usb@vger.kernel.org, davem@davemloft.net, netdev@vger.kernel.org, Petko Manolov Subject: [PATCH RESEND v3 2/2] net: rtl8150: Use the new usb control message API. Date: Sun, 27 Sep 2020 15:49:09 +0300 Message-Id: <20200927124909.16380-3-petko.manolov@konsulko.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200927124909.16380-1-petko.manolov@konsulko.com> References: <20200923134348.23862-9-oneukum@suse.com> <20200927124909.16380-1-petko.manolov@konsulko.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The old usb_control_msg() let the caller handle the error and also did not account for partial reads. Since these are now considered harmful, move the driver over to usb_control_msg_recv/send() calls. Signed-off-by: Petko Manolov --- 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..b3a0b188b1a1 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, + 1000, GFP_NOIO); } 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, + 1000, GFP_NOIO); } static void async_set_reg_cb(struct urb *urb)