From patchwork Wed Sep 23 13:43:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 258440 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 1B478C4727E for ; Wed, 23 Sep 2020 13:44:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B629521D92 for ; Wed, 23 Sep 2020 13:44:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="o9fZ1GD+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726668AbgIWNoU (ORCPT ); Wed, 23 Sep 2020 09:44:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:33198 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbgIWNoS (ORCPT ); Wed, 23 Sep 2020 09:44:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=4MkCnxprN0Wp2xxSH9di7m6bGYaZJPoL1At3UWd9ysE=; b=o9fZ1GD+IA9PEhwpX+orTd1/pckpACwkHoNHgjjBQXD9JlWGLP8ABf6TL7cYkrD33Dg+kS 56G8u3KmCu6Uts9TRsgLat5GP05Ag4V9c5hz/tzJMrjAWCM5YlEVcIckRYwtreR8053ujK SSrR/C75OUpN7+jjWCeUzcTkuZPUa74= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1E194B1AD; Wed, 23 Sep 2020 13:44:53 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Oliver Neukum Subject: [RFC 01/14] Revert "USB: core: hub.c: use usb_control_msg_send() in a few places" Date: Wed, 23 Sep 2020 15:43:35 +0200 Message-Id: <20200923134348.23862-2-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit d6a499249543356002a1efbb26254c7272e62f4c. Control messages are needed in contexts when memory allocations are restricted, such as handling device resets and runtime PM. For this reason the control message API internally uses GFP_NOIO. This is a band aid introduced because when we recognized the issue, the call chains were highly convoluted. Continuing this trend is not a good idea. So I am shooting the whole kennel here. Signed-off-by: Oliver Neukum --- drivers/usb/core/hub.c | 99 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 40 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 5742ddeb0455..5b768b80d1ee 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -410,8 +410,8 @@ static int get_hub_descriptor(struct usb_device *hdev, */ static int clear_hub_feature(struct usb_device *hdev, int feature) { - return usb_control_msg_send(hdev, 0, USB_REQ_CLEAR_FEATURE, USB_RT_HUB, - feature, 0, NULL, 0, 1000); + return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + USB_REQ_CLEAR_FEATURE, USB_RT_HUB, feature, 0, NULL, 0, 1000); } /* @@ -419,8 +419,9 @@ static int clear_hub_feature(struct usb_device *hdev, int feature) */ int usb_clear_port_feature(struct usb_device *hdev, int port1, int feature) { - return usb_control_msg_send(hdev, 0, USB_REQ_CLEAR_FEATURE, USB_RT_PORT, - feature, port1, NULL, 0, 1000); + return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port1, + NULL, 0, 1000); } /* @@ -428,8 +429,9 @@ int usb_clear_port_feature(struct usb_device *hdev, int port1, int feature) */ static int set_port_feature(struct usb_device *hdev, int port1, int feature) { - return usb_control_msg_send(hdev, 0, USB_REQ_SET_FEATURE, USB_RT_PORT, - feature, port1, NULL, 0, 1000); + return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port1, + NULL, 0, 1000); } static char *to_led_name(int selector) @@ -753,14 +755,15 @@ hub_clear_tt_buffer(struct usb_device *hdev, u16 devinfo, u16 tt) /* Need to clear both directions for control ep */ if (((devinfo >> 11) & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_CONTROL) { - int status = usb_control_msg_send(hdev, 0, - HUB_CLEAR_TT_BUFFER, USB_RT_PORT, - devinfo ^ 0x8000, tt, NULL, 0, 1000); + int status = usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + HUB_CLEAR_TT_BUFFER, USB_RT_PORT, + devinfo ^ 0x8000, tt, NULL, 0, 1000); if (status) return status; } - return usb_control_msg_send(hdev, 0, HUB_CLEAR_TT_BUFFER, USB_RT_PORT, - devinfo, tt, NULL, 0, 1000); + return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + HUB_CLEAR_TT_BUFFER, USB_RT_PORT, devinfo, + tt, NULL, 0, 1000); } /* @@ -1046,10 +1049,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) */ if (type != HUB_RESUME) { if (hdev->parent && hub_is_superspeed(hdev)) { - ret = usb_control_msg_send(hdev, 0, HUB_SET_DEPTH, USB_RT_HUB, - hdev->level - 1, 0, NULL, 0, - USB_CTRL_SET_TIMEOUT); - if (ret) + ret = usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + HUB_SET_DEPTH, USB_RT_HUB, + hdev->level - 1, 0, NULL, 0, + USB_CTRL_SET_TIMEOUT); + if (ret < 0) dev_err(hub->intfdev, "set hub depth failed\n"); } @@ -2325,10 +2329,13 @@ static int usb_enumerate_device_otg(struct usb_device *udev) /* enable HNP before suspend, it's simpler */ if (port1 == bus->otg_port) { bus->b_hnp_enable = 1; - err = usb_control_msg_send(udev, 0, USB_REQ_SET_FEATURE, 0, - USB_DEVICE_B_HNP_ENABLE, 0, - NULL, 0, USB_CTRL_SET_TIMEOUT); - if (err) { + err = usb_control_msg(udev, + usb_sndctrlpipe(udev, 0), + USB_REQ_SET_FEATURE, 0, + USB_DEVICE_B_HNP_ENABLE, + 0, NULL, 0, + USB_CTRL_SET_TIMEOUT); + if (err < 0) { /* * OTG MESSAGE: report errors here, * customize to match your product. @@ -2340,10 +2347,13 @@ static int usb_enumerate_device_otg(struct usb_device *udev) } else if (desc->bLength == sizeof (struct usb_otg_descriptor)) { /* Set a_alt_hnp_support for legacy otg device */ - err = usb_control_msg_send(udev, 0, USB_REQ_SET_FEATURE, 0, - USB_DEVICE_A_ALT_HNP_SUPPORT, 0, - NULL, 0, USB_CTRL_SET_TIMEOUT); - if (err) + err = usb_control_msg(udev, + usb_sndctrlpipe(udev, 0), + USB_REQ_SET_FEATURE, 0, + USB_DEVICE_A_ALT_HNP_SUPPORT, + 0, NULL, 0, + USB_CTRL_SET_TIMEOUT); + if (err < 0) dev_err(&udev->dev, "set a_alt_hnp_support failed: %d\n", err); @@ -3111,8 +3121,10 @@ int usb_disable_ltm(struct usb_device *udev) if (!udev->actconfig) return 0; - return usb_control_msg_send(udev, 0, USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, - USB_DEVICE_LTM_ENABLE, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); + return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, + USB_DEVICE_LTM_ENABLE, 0, NULL, 0, + USB_CTRL_SET_TIMEOUT); } EXPORT_SYMBOL_GPL(usb_disable_ltm); @@ -3131,8 +3143,10 @@ void usb_enable_ltm(struct usb_device *udev) if (!udev->actconfig) return; - usb_control_msg_send(udev, 0, USB_REQ_SET_FEATURE, USB_RECIP_DEVICE, - USB_DEVICE_LTM_ENABLE, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); + usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + USB_REQ_SET_FEATURE, USB_RECIP_DEVICE, + USB_DEVICE_LTM_ENABLE, 0, NULL, 0, + USB_CTRL_SET_TIMEOUT); } EXPORT_SYMBOL_GPL(usb_enable_ltm); @@ -3149,14 +3163,17 @@ EXPORT_SYMBOL_GPL(usb_enable_ltm); static int usb_enable_remote_wakeup(struct usb_device *udev) { if (udev->speed < USB_SPEED_SUPER) - return usb_control_msg_send(udev, 0, USB_REQ_SET_FEATURE, USB_RECIP_DEVICE, - USB_DEVICE_REMOTE_WAKEUP, 0, - NULL, 0, USB_CTRL_SET_TIMEOUT); + return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + USB_REQ_SET_FEATURE, USB_RECIP_DEVICE, + USB_DEVICE_REMOTE_WAKEUP, 0, NULL, 0, + USB_CTRL_SET_TIMEOUT); else - return usb_control_msg_send(udev, 0, USB_REQ_SET_FEATURE, USB_RECIP_INTERFACE, - USB_INTRF_FUNC_SUSPEND, - USB_INTRF_FUNC_SUSPEND_RW | USB_INTRF_FUNC_SUSPEND_LP, - NULL, 0, USB_CTRL_SET_TIMEOUT); + return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + USB_REQ_SET_FEATURE, USB_RECIP_INTERFACE, + USB_INTRF_FUNC_SUSPEND, + USB_INTRF_FUNC_SUSPEND_RW | + USB_INTRF_FUNC_SUSPEND_LP, + NULL, 0, USB_CTRL_SET_TIMEOUT); } /* @@ -3172,13 +3189,15 @@ static int usb_enable_remote_wakeup(struct usb_device *udev) static int usb_disable_remote_wakeup(struct usb_device *udev) { if (udev->speed < USB_SPEED_SUPER) - return usb_control_msg_send(udev, 0, USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, - USB_DEVICE_REMOTE_WAKEUP, 0, NULL, 0, - USB_CTRL_SET_TIMEOUT); + return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, + USB_DEVICE_REMOTE_WAKEUP, 0, NULL, 0, + USB_CTRL_SET_TIMEOUT); else - return usb_control_msg_send(udev, 0, USB_REQ_SET_FEATURE, USB_RECIP_INTERFACE, - USB_INTRF_FUNC_SUSPEND, 0, NULL, 0, - USB_CTRL_SET_TIMEOUT); + return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + USB_REQ_SET_FEATURE, USB_RECIP_INTERFACE, + USB_INTRF_FUNC_SUSPEND, 0, NULL, 0, + USB_CTRL_SET_TIMEOUT); } /* Count of wakeup-enabled devices at or below udev */ From patchwork Wed Sep 23 13:43:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 297534 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 120DEC4727E for ; Wed, 23 Sep 2020 13:44:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C755821D92 for ; Wed, 23 Sep 2020 13:44:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="OZslMne+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726636AbgIWNoS (ORCPT ); Wed, 23 Sep 2020 09:44:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:33228 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726559AbgIWNoR (ORCPT ); Wed, 23 Sep 2020 09:44:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=zaFxZgwCHaNkcErl7geMWUuzHB8/NPepO7loIcMVOeU=; b=OZslMne+vGrN9lht64ypJ3t/dQK5Tgbw5fo45hmwfZYGm7E3qcA+rvrkF+/AGbIalzLokk bypO2IQpONYqA+DN5My7mAOKZsnNEh00R/uGCxkxWwoNvs7fYvKkbyfwVobCahtABNOMdD Njd+lXZTCYhV+ZBLldxLDZdER+g+yGQ= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 368B0AD2C; Wed, 23 Sep 2020 13:44:53 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Oliver Neukum Subject: [RFC 02/14] Revert "Bluetooth: ath3k: use usb_control_msg_send() and usb_control_msg_recv()" Date: Wed, 23 Sep 2020 15:43:36 +0200 Message-Id: <20200923134348.23862-3-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit e9b20f0fe17ab06c3b55153046209987749daa48. The API has to be changed Signed-off-by: Oliver Neukum --- drivers/bluetooth/ath3k.c | 90 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 26 deletions(-) diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c index 1472cccfd0b3..4ce270513695 100644 --- a/drivers/bluetooth/ath3k.c +++ b/drivers/bluetooth/ath3k.c @@ -212,16 +212,19 @@ static int ath3k_load_firmware(struct usb_device *udev, BT_DBG("udev %p", udev); + pipe = usb_sndctrlpipe(udev, 0); + send_buf = kmalloc(BULK_SIZE, GFP_KERNEL); if (!send_buf) { BT_ERR("Can't allocate memory chunk for firmware"); return -ENOMEM; } - err = usb_control_msg_send(udev, 0, USB_REQ_DFU_DNLOAD, USB_TYPE_VENDOR, - 0, 0, firmware->data, FW_HDR_SIZE, - USB_CTRL_SET_TIMEOUT); - if (err) { + memcpy(send_buf, firmware->data, FW_HDR_SIZE); + err = usb_control_msg(udev, pipe, USB_REQ_DFU_DNLOAD, USB_TYPE_VENDOR, + 0, 0, send_buf, FW_HDR_SIZE, + USB_CTRL_SET_TIMEOUT); + if (err < 0) { BT_ERR("Can't change to loading configuration err"); goto error; } @@ -256,17 +259,44 @@ static int ath3k_load_firmware(struct usb_device *udev, static int ath3k_get_state(struct usb_device *udev, unsigned char *state) { - return usb_control_msg_recv(udev, 0, ATH3K_GETSTATE, - USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, - state, 1, USB_CTRL_SET_TIMEOUT); + int ret, pipe = 0; + char *buf; + + buf = kmalloc(sizeof(*buf), GFP_KERNEL); + if (!buf) + return -ENOMEM; + + pipe = usb_rcvctrlpipe(udev, 0); + ret = usb_control_msg(udev, pipe, ATH3K_GETSTATE, + USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, + buf, sizeof(*buf), USB_CTRL_SET_TIMEOUT); + + *state = *buf; + kfree(buf); + + return ret; } static int ath3k_get_version(struct usb_device *udev, struct ath3k_version *version) { - return usb_control_msg_recv(udev, 0, ATH3K_GETVERSION, - USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, - version, sizeof(*version), USB_CTRL_SET_TIMEOUT); + int ret, pipe = 0; + struct ath3k_version *buf; + const int size = sizeof(*buf); + + buf = kmalloc(size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + pipe = usb_rcvctrlpipe(udev, 0); + ret = usb_control_msg(udev, pipe, ATH3K_GETVERSION, + USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, + buf, size, USB_CTRL_SET_TIMEOUT); + + memcpy(version, buf, size); + kfree(buf); + + return ret; } static int ath3k_load_fwfile(struct usb_device *udev, @@ -286,10 +316,13 @@ static int ath3k_load_fwfile(struct usb_device *udev, } size = min_t(uint, count, FW_HDR_SIZE); + memcpy(send_buf, firmware->data, size); - ret = usb_control_msg_send(udev, 0, ATH3K_DNLOAD, USB_TYPE_VENDOR, 0, 0, - firmware->data, size, USB_CTRL_SET_TIMEOUT); - if (ret) { + pipe = usb_sndctrlpipe(udev, 0); + ret = usb_control_msg(udev, pipe, ATH3K_DNLOAD, + USB_TYPE_VENDOR, 0, 0, send_buf, + size, USB_CTRL_SET_TIMEOUT); + if (ret < 0) { BT_ERR("Can't change to loading configuration err"); kfree(send_buf); return ret; @@ -322,19 +355,23 @@ static int ath3k_load_fwfile(struct usb_device *udev, return 0; } -static void ath3k_switch_pid(struct usb_device *udev) +static int ath3k_switch_pid(struct usb_device *udev) { - usb_control_msg_send(udev, 0, USB_REG_SWITCH_VID_PID, USB_TYPE_VENDOR, - 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); + int pipe = 0; + + pipe = usb_sndctrlpipe(udev, 0); + return usb_control_msg(udev, pipe, USB_REG_SWITCH_VID_PID, + USB_TYPE_VENDOR, 0, 0, + NULL, 0, USB_CTRL_SET_TIMEOUT); } static int ath3k_set_normal_mode(struct usb_device *udev) { unsigned char fw_state; - int ret; + int pipe = 0, ret; ret = ath3k_get_state(udev, &fw_state); - if (ret) { + if (ret < 0) { BT_ERR("Can't get state to change to normal mode err"); return ret; } @@ -344,9 +381,10 @@ static int ath3k_set_normal_mode(struct usb_device *udev) return 0; } - return usb_control_msg_send(udev, 0, ATH3K_SET_NORMAL_MODE, - USB_TYPE_VENDOR, 0, 0, NULL, 0, - USB_CTRL_SET_TIMEOUT); + pipe = usb_sndctrlpipe(udev, 0); + return usb_control_msg(udev, pipe, ATH3K_SET_NORMAL_MODE, + USB_TYPE_VENDOR, 0, 0, + NULL, 0, USB_CTRL_SET_TIMEOUT); } static int ath3k_load_patch(struct usb_device *udev) @@ -359,7 +397,7 @@ static int ath3k_load_patch(struct usb_device *udev) int ret; ret = ath3k_get_state(udev, &fw_state); - if (ret) { + if (ret < 0) { BT_ERR("Can't get state to change to load ram patch err"); return ret; } @@ -370,7 +408,7 @@ static int ath3k_load_patch(struct usb_device *udev) } ret = ath3k_get_version(udev, &fw_version); - if (ret) { + if (ret < 0) { BT_ERR("Can't get version to change to load ram patch err"); return ret; } @@ -411,13 +449,13 @@ static int ath3k_load_syscfg(struct usb_device *udev) int clk_value, ret; ret = ath3k_get_state(udev, &fw_state); - if (ret) { + if (ret < 0) { BT_ERR("Can't get state to change to load configuration err"); return -EBUSY; } ret = ath3k_get_version(udev, &fw_version); - if (ret) { + if (ret < 0) { BT_ERR("Can't get version to change to load ram patch err"); return ret; } @@ -491,7 +529,7 @@ static int ath3k_probe(struct usb_interface *intf, return ret; } ret = ath3k_set_normal_mode(udev); - if (ret) { + if (ret < 0) { BT_ERR("Set normal mode failed"); return ret; } From patchwork Wed Sep 23 13:43:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 258444 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 D96F3C2D0E2 for ; Wed, 23 Sep 2020 13:44:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A17521D92 for ; Wed, 23 Sep 2020 13:44:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="OlVrevRP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726634AbgIWNoS (ORCPT ); Wed, 23 Sep 2020 09:44:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:33262 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbgIWNoR (ORCPT ); Wed, 23 Sep 2020 09:44:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=1hqk9ObDxCKsKp4GqrA4+fwCY6EqqtELv1CP5bt9GuI=; b=OlVrevRPIzuTFIUqjHS9GecVbCyCBDyX9tiqRSocy27HxAx9ClrHd9ZQ1DSUYCJo27hz9a pn5br/CeSXCPSQik5XUih+tjLOFgKU1n+8z/RGPcW1RIiMjxLpzbFTUoDerI98NjVH05uk WFB4y/oSeLIdIVGCC4WtalQJNjynYBw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6CBA9AD57; Wed, 23 Sep 2020 13:44:53 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Oliver Neukum Subject: [RFC 03/14] Revert "sound: hiface: move to use usb_control_msg_send()" Date: Wed, 23 Sep 2020 15:43:37 +0200 Message-Id: <20200923134348.23862-4-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit 119ae38a5cdfbefdf926b34fbf65cd60dc82c95e. The API has to be changed. Signed-off-by: Oliver Neukum --- sound/usb/hiface/pcm.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sound/usb/hiface/pcm.c b/sound/usb/hiface/pcm.c index f9c924e3964e..a148caa5f48e 100644 --- a/sound/usb/hiface/pcm.c +++ b/sound/usb/hiface/pcm.c @@ -156,14 +156,16 @@ static int hiface_pcm_set_rate(struct pcm_runtime *rt, unsigned int rate) * This control message doesn't have any ack from the * other side */ - ret = usb_control_msg_send(device, 0, - HIFACE_SET_RATE_REQUEST, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, - rate_value, 0, NULL, 0, 100); - if (ret) + ret = usb_control_msg(device, usb_sndctrlpipe(device, 0), + HIFACE_SET_RATE_REQUEST, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, + rate_value, 0, NULL, 0, 100); + if (ret < 0) { dev_err(&device->dev, "Error setting samplerate %d.\n", rate); + return ret; + } - return ret; + return 0; } static struct pcm_substream *hiface_pcm_get_substream(struct snd_pcm_substream From patchwork Wed Sep 23 13:43:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 258438 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 98A04C4727E for ; Wed, 23 Sep 2020 13:44:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49C8321D92 for ; Wed, 23 Sep 2020 13:44:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="rEQ7U6ur" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbgIWNoa (ORCPT ); Wed, 23 Sep 2020 09:44:30 -0400 Received: from mx2.suse.de ([195.135.220.15]:33286 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726620AbgIWNoS (ORCPT ); Wed, 23 Sep 2020 09:44:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=V6JRcipxax8FcSm4zmu9Qp+/xjOsZSxBR9zTTxqihxc=; b=rEQ7U6urZ0rygxvWqor5CT7txptNaEWAWL7zyQAFZaCI2UC9i53x2wOgT+HfdwLiUoJAFw mewRR9OvnfgKg144HLipECuuyFI7Q9IMN5wGSEP8Cqlr8CagBdPrFaCbi8wJrxX4/H8Vks yN2052oBOr9ra+k/MAm4Ay+Gywfine8= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9C6B7ADBB; Wed, 23 Sep 2020 13:44:53 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Oliver Neukum Subject: [RFC 04/14] Revert "sound: line6: move to use usb_control_msg_send() and usb_control_msg_recv()" Date: Wed, 23 Sep 2020 15:43:38 +0200 Message-Id: <20200923134348.23862-5-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit f7ef7614f89e943d7511ee121b0b849f27b60cb2. The API has to be changed. Signed-off-by: Oliver Neukum --- sound/usb/line6/driver.c | 69 ++++++++++++++++++++++++++++------------------ sound/usb/line6/podhd.c | 17 ++++++++---- sound/usb/line6/toneport.c | 8 +++--- 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c index 601292c51491..60674ce4879b 100644 --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -337,18 +337,23 @@ int line6_read_data(struct usb_line6 *line6, unsigned address, void *data, { struct usb_device *usbdev = line6->usbdev; int ret; - u8 len; + unsigned char *len; unsigned count; if (address > 0xffff || datalen > 0xff) return -EINVAL; + len = kmalloc(1, GFP_KERNEL); + if (!len) + return -ENOMEM; + /* query the serial number: */ - ret = usb_control_msg_send(usbdev, 0, 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, - (datalen << 8) | 0x21, address, NULL, 0, - LINE6_TIMEOUT * HZ); - if (ret) { + ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, + (datalen << 8) | 0x21, address, + NULL, 0, LINE6_TIMEOUT * HZ); + + if (ret < 0) { dev_err(line6->ifcdev, "read request failed (error %d)\n", ret); goto exit; } @@ -357,41 +362,45 @@ int line6_read_data(struct usb_line6 *line6, unsigned address, void *data, for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) { mdelay(LINE6_READ_WRITE_STATUS_DELAY); - ret = usb_control_msg_recv(usbdev, 0, 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, - 0x0012, 0x0000, &len, 1, - LINE6_TIMEOUT * HZ); - if (ret) { + ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | + USB_DIR_IN, + 0x0012, 0x0000, len, 1, + LINE6_TIMEOUT * HZ); + if (ret < 0) { dev_err(line6->ifcdev, "receive length failed (error %d)\n", ret); goto exit; } - if (len != 0xff) + if (*len != 0xff) break; } ret = -EIO; - if (len == 0xff) { + if (*len == 0xff) { dev_err(line6->ifcdev, "read failed after %d retries\n", count); goto exit; - } else if (len != datalen) { + } else if (*len != datalen) { /* should be equal or something went wrong */ dev_err(line6->ifcdev, "length mismatch (expected %d, got %d)\n", - (int)datalen, len); + (int)datalen, (int)*len); goto exit; } /* receive the result: */ - ret = usb_control_msg_recv(usbdev, 0, 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, - 0x0013, 0x0000, data, datalen, LINE6_TIMEOUT * HZ); - if (ret) + ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, + 0x0013, 0x0000, data, datalen, + LINE6_TIMEOUT * HZ); + + if (ret < 0) dev_err(line6->ifcdev, "read failed (error %d)\n", ret); exit: + kfree(len); return ret; } EXPORT_SYMBOL_GPL(line6_read_data); @@ -414,10 +423,12 @@ int line6_write_data(struct usb_line6 *line6, unsigned address, void *data, if (!status) return -ENOMEM; - ret = usb_control_msg_send(usbdev, 0, 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, - 0x0022, address, data, datalen, LINE6_TIMEOUT * HZ); - if (ret) { + ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, + 0x0022, address, data, datalen, + LINE6_TIMEOUT * HZ); + + if (ret < 0) { dev_err(line6->ifcdev, "write request failed (error %d)\n", ret); goto exit; @@ -426,10 +437,14 @@ int line6_write_data(struct usb_line6 *line6, unsigned address, void *data, for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) { mdelay(LINE6_READ_WRITE_STATUS_DELAY); - ret = usb_control_msg_recv(usbdev, 0, 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, - 0x0012, 0x0000, status, 1, LINE6_TIMEOUT * HZ); - if (ret) { + ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), + 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | + USB_DIR_IN, + 0x0012, 0x0000, + status, 1, LINE6_TIMEOUT * HZ); + + if (ret < 0) { dev_err(line6->ifcdev, "receiving status failed (error %d)\n", ret); goto exit; diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c index a1261f55d62b..eef45f7fef0d 100644 --- a/sound/usb/line6/podhd.c +++ b/sound/usb/line6/podhd.c @@ -183,25 +183,29 @@ static const struct attribute_group podhd_dev_attr_group = { static int podhd_dev_start(struct usb_line6_podhd *pod) { int ret; - u8 init_bytes[8]; + u8 *init_bytes; int i; struct usb_device *usbdev = pod->line6.usbdev; - ret = usb_control_msg_send(usbdev, 0, + init_bytes = kmalloc(8, GFP_KERNEL); + if (!init_bytes) + return -ENOMEM; + + ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, 0x11, 0, NULL, 0, LINE6_TIMEOUT * HZ); - if (ret) { + if (ret < 0) { dev_err(pod->line6.ifcdev, "read request failed (error %d)\n", ret); goto exit; } /* NOTE: looks like some kind of ping message */ - ret = usb_control_msg_recv(usbdev, 0, 0x67, + ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 0x11, 0x0, init_bytes, 3, LINE6_TIMEOUT * HZ); - if (ret) { + if (ret < 0) { dev_err(pod->line6.ifcdev, "receive length failed (error %d)\n", ret); goto exit; @@ -216,12 +220,13 @@ static int podhd_dev_start(struct usb_line6_podhd *pod) goto exit; } - ret = usb_control_msg_send(usbdev, 0, + ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), USB_REQ_SET_FEATURE, USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_DIR_OUT, 1, 0, NULL, 0, LINE6_TIMEOUT * HZ); exit: + kfree(init_bytes); return ret; } diff --git a/sound/usb/line6/toneport.c b/sound/usb/line6/toneport.c index a9b56085b76a..94dd5e7ab2e6 100644 --- a/sound/usb/line6/toneport.c +++ b/sound/usb/line6/toneport.c @@ -126,11 +126,11 @@ static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2) { int ret; - ret = usb_control_msg_send(usbdev, 0, 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, - cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ); + ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, + cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ); - if (ret) { + if (ret < 0) { dev_err(&usbdev->dev, "send failed (error %d)\n", ret); return ret; } From patchwork Wed Sep 23 13:43:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 258442 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=-10.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,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 F2065C4741F for ; Wed, 23 Sep 2020 13:44:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A34DA21D92 for ; Wed, 23 Sep 2020 13:44:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="NYKRF1l9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726632AbgIWNoW (ORCPT ); Wed, 23 Sep 2020 09:44:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:33436 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgIWNoT (ORCPT ); Wed, 23 Sep 2020 09:44:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=jWlZzVcLaX5SUMbRVSLkTMFn2o+DHHEtT5myBaffZPA=; b=NYKRF1l9vD5AdXT+5F5iSUK+FTgS09gjtQCuLHWufj0hu9vM0eaBNIS7u+l3fR/+efnPqw AsTNQURplOGq6L3tKpFqwyTUGSYQfniZaxaukDP/QXcG/VE0fVP0AV/L7AYi1LlIRxKMxU Z76l/8t+LtkRG8wq/OLCUWCfb+RxYEU= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D2954AC55; Wed, 23 Sep 2020 13:44:53 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Oliver Neukum Subject: [RFC 05/14] Revert "sound: 6fire: move to use usb_control_msg_send() and usb_control_msg_recv()" Date: Wed, 23 Sep 2020 15:43:39 +0200 Message-Id: <20200923134348.23862-6-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit aea67cc1418252d07b9b56688f1b5fa70fcae813. The API has to be changed. Signed-off-by: Oliver Neukum --- sound/usb/6fire/firmware.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/sound/usb/6fire/firmware.c b/sound/usb/6fire/firmware.c index 5b8994070c96..69137c14d0dc 100644 --- a/sound/usb/6fire/firmware.c +++ b/sound/usb/6fire/firmware.c @@ -158,17 +158,29 @@ static int usb6fire_fw_ihex_init(const struct firmware *fw, static int usb6fire_fw_ezusb_write(struct usb_device *device, int type, int value, char *data, int len) { - return usb_control_msg_send(device, 0, type, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - value, 0, data, len, HZ); + int ret; + + ret = usb_control_msg(device, usb_sndctrlpipe(device, 0), type, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + value, 0, data, len, HZ); + if (ret < 0) + return ret; + else if (ret != len) + return -EIO; + return 0; } static int usb6fire_fw_ezusb_read(struct usb_device *device, int type, int value, char *data, int len) { - return usb_control_msg_recv(device, 0, type, - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - value, 0, data, len, HZ); + int ret = usb_control_msg(device, usb_rcvctrlpipe(device, 0), type, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, value, + 0, data, len, HZ); + if (ret < 0) + return ret; + else if (ret != len) + return -EIO; + return 0; } static int usb6fire_fw_fpga_write(struct usb_device *device, @@ -218,7 +230,7 @@ static int usb6fire_fw_ezusb_upload( /* upload firmware image */ data = 0x01; /* stop ezusb cpu */ ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1); - if (ret) { + if (ret < 0) { kfree(rec); release_firmware(fw); dev_err(&intf->dev, @@ -230,7 +242,7 @@ static int usb6fire_fw_ezusb_upload( while (usb6fire_fw_ihex_next_record(rec)) { /* write firmware */ ret = usb6fire_fw_ezusb_write(device, 0xa0, rec->address, rec->data, rec->len); - if (ret) { + if (ret < 0) { kfree(rec); release_firmware(fw); dev_err(&intf->dev, @@ -245,7 +257,7 @@ static int usb6fire_fw_ezusb_upload( if (postdata) { /* write data after firmware has been uploaded */ ret = usb6fire_fw_ezusb_write(device, 0xa0, postaddr, postdata, postlen); - if (ret) { + if (ret < 0) { dev_err(&intf->dev, "unable to upload ezusb firmware %s: post urb.\n", fwname); @@ -255,7 +267,7 @@ static int usb6fire_fw_ezusb_upload( data = 0x00; /* resume ezusb cpu */ ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1); - if (ret) { + if (ret < 0) { dev_err(&intf->dev, "unable to upload ezusb firmware %s: end message.\n", fwname); @@ -290,7 +302,7 @@ static int usb6fire_fw_fpga_upload( end = fw->data + fw->size; ret = usb6fire_fw_ezusb_write(device, 8, 0, NULL, 0); - if (ret) { + if (ret < 0) { kfree(buffer); release_firmware(fw); dev_err(&intf->dev, @@ -315,7 +327,7 @@ static int usb6fire_fw_fpga_upload( kfree(buffer); ret = usb6fire_fw_ezusb_write(device, 9, 0, NULL, 0); - if (ret) { + if (ret < 0) { dev_err(&intf->dev, "unable to upload fpga firmware: end urb.\n"); return ret; @@ -351,7 +363,7 @@ int usb6fire_fw_init(struct usb_interface *intf) u8 buffer[12]; ret = usb6fire_fw_ezusb_read(device, 1, 0, buffer, 8); - if (ret) { + if (ret < 0) { dev_err(&intf->dev, "unable to receive device firmware state.\n"); return ret; From patchwork Wed Sep 23 13:43:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 297533 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 3A625C2D0A8 for ; Wed, 23 Sep 2020 13:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1A8E21D92 for ; Wed, 23 Sep 2020 13:44:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="C2RWhmxR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726670AbgIWNoU (ORCPT ); Wed, 23 Sep 2020 09:44:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:33434 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726504AbgIWNoT (ORCPT ); Wed, 23 Sep 2020 09:44:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=4yQO5dvm56CHVNtVMdAMru2KacTYIoVq4tbBEx254NA=; b=C2RWhmxRGcFCmoCYz7fRYvMb1PVDIZiEl840168BOzktv8M0sFE8ph8dFgGGRUhkiVtdtB a6AD1Y7AlfvxExlWh7f0/FCJJ8aSlABl4AaRPSTTqPvIRjJWZqm102oLZ6TCNeEji/BvPR k+rdh3qls0Ul1RtAIC5yi/978g3WxEw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 13C59AD46; Wed, 23 Sep 2020 13:44:54 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Oliver Neukum Subject: [RFC 06/14] Revert "sound: usx2y: move to use usb_control_msg_send()" Date: Wed, 23 Sep 2020 15:43:40 +0200 Message-Id: <20200923134348.23862-7-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit ec8eeceb06b7a6efb6d924fd2f4ba4ec79ddc7bf. The API has to be changed. Signed-off-by: Oliver Neukum --- sound/usb/usx2y/us122l.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c index 6d35303b0948..f86f7a61fb36 100644 --- a/sound/usb/usx2y/us122l.c +++ b/sound/usb/usx2y/us122l.c @@ -82,13 +82,40 @@ static int us144_create_usbmidi(struct snd_card *card) &US122L(card)->midi_list, &quirk); } +/* + * Wrapper for usb_control_msg(). + * Allocates a temp buffer to prevent dmaing from/to the stack. + */ +static int us122l_ctl_msg(struct usb_device *dev, unsigned int pipe, + __u8 request, __u8 requesttype, + __u16 value, __u16 index, void *data, + __u16 size, int timeout) +{ + int err; + void *buf = NULL; + + if (size > 0) { + buf = kmemdup(data, size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + } + err = usb_control_msg(dev, pipe, request, requesttype, + value, index, buf, size, timeout); + if (size > 0) { + memcpy(data, buf, size); + kfree(buf); + } + return err; +} + static void pt_info_set(struct usb_device *dev, u8 v) { int ret; - ret = usb_control_msg_send(dev, 0, 'I', - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - v, 0, NULL, 0, 1000); + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + 'I', + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + v, 0, NULL, 0, 1000); snd_printdd(KERN_DEBUG "%i\n", ret); } @@ -278,11 +305,10 @@ static int us122l_set_sample_rate(struct usb_device *dev, int rate) data[0] = rate; data[1] = rate >> 8; data[2] = rate >> 16; - err = usb_control_msg_send(dev, 0, UAC_SET_CUR, - USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, - UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, - 1000); - if (err) + err = us122l_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, + USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, + UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, 1000); + if (err < 0) snd_printk(KERN_ERR "%d: cannot set freq %d to ep 0x%x\n", dev->devnum, rate, ep); return err; From patchwork Wed Sep 23 13:43:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 258443 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 5CF07C4727F for ; Wed, 23 Sep 2020 13:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B1DF2220D for ; Wed, 23 Sep 2020 13:44:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="s51Yd8db" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726671AbgIWNoU (ORCPT ); Wed, 23 Sep 2020 09:44:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:33442 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726630AbgIWNoT (ORCPT ); Wed, 23 Sep 2020 09:44:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=vfC9XPNad+kdZK1rgemg6BP3RZYWacVZU0lxrppC9Lc=; b=s51Yd8db9ccRb+7WiAuENgjo0NO8v5sWqPXOGDt8T1034qClHC5HFIi07AGWDBM6Luoto/ f2s5LujxYG+JFRYnrb9HbA95t2V96kPy6H4rtym0ACJdoECx14jFGV2Rvi5oU3E75522mW qFzS581omUDJk0vSk8HlDvFVnq0UVvI= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4A17EB164; Wed, 23 Sep 2020 13:44:54 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Oliver Neukum Subject: [RFC 07/14] Revert "USB: legousbtower: use usb_control_msg_recv()" Date: Wed, 23 Sep 2020 15:43:41 +0200 Message-Id: <20200923134348.23862-8-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit be40c366416bf6ff74b25fd02e38cb6eaba497d1. The API has to be changed. Signed-off-by: Oliver Neukum --- drivers/usb/misc/legousbtower.c | 60 ++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c index c3583df4c324..f922544056de 100644 --- a/drivers/usb/misc/legousbtower.c +++ b/drivers/usb/misc/legousbtower.c @@ -308,9 +308,15 @@ static int tower_open(struct inode *inode, struct file *file) int subminor; int retval = 0; struct usb_interface *interface; - struct tower_reset_reply reset_reply; + struct tower_reset_reply *reset_reply; int result; + reset_reply = kmalloc(sizeof(*reset_reply), GFP_KERNEL); + if (!reset_reply) { + retval = -ENOMEM; + goto exit; + } + nonseekable_open(inode, file); subminor = iminor(inode); @@ -341,11 +347,15 @@ static int tower_open(struct inode *inode, struct file *file) } /* reset the tower */ - result = usb_control_msg_recv(dev->udev, 0, - LEGO_USB_TOWER_REQUEST_RESET, - USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE, - 0, 0, - &reset_reply, sizeof(reset_reply), 1000); + result = usb_control_msg(dev->udev, + usb_rcvctrlpipe(dev->udev, 0), + LEGO_USB_TOWER_REQUEST_RESET, + USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE, + 0, + 0, + reset_reply, + sizeof(*reset_reply), + 1000); if (result < 0) { dev_err(&dev->udev->dev, "LEGO USB Tower reset control request failed\n"); @@ -384,6 +394,7 @@ static int tower_open(struct inode *inode, struct file *file) mutex_unlock(&dev->lock); exit: + kfree(reset_reply); return retval; } @@ -742,7 +753,7 @@ static int tower_probe(struct usb_interface *interface, const struct usb_device_ struct device *idev = &interface->dev; struct usb_device *udev = interface_to_usbdev(interface); struct lego_usb_tower *dev; - struct tower_get_version_reply get_version_reply; + struct tower_get_version_reply *get_version_reply = NULL; int retval = -ENOMEM; int result; @@ -787,25 +798,34 @@ static int tower_probe(struct usb_interface *interface, const struct usb_device_ dev->interrupt_in_interval = interrupt_in_interval ? interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; dev->interrupt_out_interval = interrupt_out_interval ? interrupt_out_interval : dev->interrupt_out_endpoint->bInterval; + get_version_reply = kmalloc(sizeof(*get_version_reply), GFP_KERNEL); + if (!get_version_reply) { + retval = -ENOMEM; + goto error; + } + /* get the firmware version and log it */ - result = usb_control_msg_recv(udev, 0, - LEGO_USB_TOWER_REQUEST_GET_VERSION, - USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE, - 0, - 0, - &get_version_reply, - sizeof(get_version_reply), - 1000); - if (!result) { + result = usb_control_msg(udev, + usb_rcvctrlpipe(udev, 0), + LEGO_USB_TOWER_REQUEST_GET_VERSION, + USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE, + 0, + 0, + get_version_reply, + sizeof(*get_version_reply), + 1000); + if (result != sizeof(*get_version_reply)) { + if (result >= 0) + result = -EIO; dev_err(idev, "get version request failed: %d\n", result); retval = result; goto error; } dev_info(&interface->dev, "LEGO USB Tower firmware version is %d.%d build %d\n", - get_version_reply.major, - get_version_reply.minor, - le16_to_cpu(get_version_reply.build_no)); + get_version_reply->major, + get_version_reply->minor, + le16_to_cpu(get_version_reply->build_no)); /* we can register the device now, as it is ready */ usb_set_intfdata(interface, dev); @@ -824,9 +844,11 @@ static int tower_probe(struct usb_interface *interface, const struct usb_device_ USB_MAJOR, dev->minor); exit: + kfree(get_version_reply); return retval; error: + kfree(get_version_reply); tower_delete(dev); return retval; } From patchwork Wed Sep 23 13:43:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 297529 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 9B759C2D0E2 for ; Wed, 23 Sep 2020 13:44:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44FF1221EB for ; Wed, 23 Sep 2020 13:44:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="APPqQsXi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726582AbgIWNo1 (ORCPT ); Wed, 23 Sep 2020 09:44:27 -0400 Received: from mx2.suse.de ([195.135.220.15]:33504 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbgIWNoU (ORCPT ); Wed, 23 Sep 2020 09:44:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=0j5VCmMIJ14KVmA4epSj7Ta0DdTeBsCFpXJBB5X6zEA=; b=APPqQsXizDvNRgCGp2WDWpaaOu52zh3eGM6rl56Kiw8Q3hL1/J30qFXVaEjnuID9uV9+YB gJQTb1sWAaXytH0Rg8yCrsZnhFNFQu8vlJb4PSFtr/56LCaI7NY0P9yMpu1oe47HRF/0FO q8lBHb363NX0JY7UxG2Ubleg3acKUQY= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B853AB1A4; Wed, 23 Sep 2020 13:44:54 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Jaroslav Kysela Subject: [RFC 09/14] sound: usx2y: move to use usb_control_msg_send() Date: Wed, 23 Sep 2020 15:43:43 +0200 Message-Id: <20200923134348.23862-10-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Greg Kroah-Hartman The usb_control_msg_send() call can handle data on the stack, as well as returning an error if a "short" write happens, so move the driver over to using that call instead. This ends up removing a helper function that is no longer needed. v2: API change in usb_control_msg_send() Cc: Jaroslav Kysela Reviewed-by: Takashi Iwai Link: https://lore.kernel.org/r/20200914153756.3412156-7-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- sound/usb/usx2y/us122l.c | 44 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c index f86f7a61fb36..3614e6802dc1 100644 --- a/sound/usb/usx2y/us122l.c +++ b/sound/usb/usx2y/us122l.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-License-Identifier: GPL-2.0-or-late /* * Copyright (C) 2007, 2008 Karsten Wiese */ @@ -82,40 +82,13 @@ static int us144_create_usbmidi(struct snd_card *card) &US122L(card)->midi_list, &quirk); } -/* - * Wrapper for usb_control_msg(). - * Allocates a temp buffer to prevent dmaing from/to the stack. - */ -static int us122l_ctl_msg(struct usb_device *dev, unsigned int pipe, - __u8 request, __u8 requesttype, - __u16 value, __u16 index, void *data, - __u16 size, int timeout) -{ - int err; - void *buf = NULL; - - if (size > 0) { - buf = kmemdup(data, size, GFP_KERNEL); - if (!buf) - return -ENOMEM; - } - err = usb_control_msg(dev, pipe, request, requesttype, - value, index, buf, size, timeout); - if (size > 0) { - memcpy(data, buf, size); - kfree(buf); - } - return err; -} - static void pt_info_set(struct usb_device *dev, u8 v) { int ret; - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - 'I', - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - v, 0, NULL, 0, 1000); + ret = usb_control_msg_send(dev, 0, 'I', + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + v, 0, NULL, 0, 1000, GFP_NOIO); snd_printdd(KERN_DEBUG "%i\n", ret); } @@ -305,10 +278,11 @@ static int us122l_set_sample_rate(struct usb_device *dev, int rate) data[0] = rate; data[1] = rate >> 8; data[2] = rate >> 16; - err = us122l_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, - USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, - UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, 1000); - if (err < 0) + err = usb_control_msg_send(dev, 0, UAC_SET_CUR, + USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, + UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, + 1000, GFP_NOIO); + if (err) snd_printk(KERN_ERR "%d: cannot set freq %d to ep 0x%x\n", dev->devnum, rate, ep); return err; From patchwork Wed Sep 23 13:43:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 297528 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=-10.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,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 DF1EFC4741F for ; Wed, 23 Sep 2020 13:44:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8EF0A221EB for ; Wed, 23 Sep 2020 13:44:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="jpf0lZ2O" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726648AbgIWNo2 (ORCPT ); Wed, 23 Sep 2020 09:44:28 -0400 Received: from mx2.suse.de ([195.135.220.15]:33506 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726559AbgIWNoU (ORCPT ); Wed, 23 Sep 2020 09:44:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=bF/M6kO+6HGy/pk4qX7hm30BYO7RKvsPIUtHc1S91pU=; b=jpf0lZ2OuXtLq6Z04fQeVD3tQz8wyp46hWX2mXvByJrQv4nl2O7jTHKqXMov2ktGpJJwgs PMsnZ0tdOhp0aJhiDvJtWGYGCiLaPLu+xkNX1GDiJ4nGarMbikNGtvz/QE+RU6b+z81i6m rFpMyBRz56jb+FqK5ES74CvbvTMQd2M= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id F2111B1AB; Wed, 23 Sep 2020 13:44:54 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Jaroslav Kysela Subject: [RFC 10/14] sound: 6fire: move to use usb_control_msg_send() and usb_control_msg_recv() Date: Wed, 23 Sep 2020 15:43:44 +0200 Message-Id: <20200923134348.23862-11-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Greg Kroah-Hartman The usb_control_msg_send() and usb_control_msg_recv() calls can return an error if a "short" write/read happens, so move the driver over to using those calls instead, saving some logic in the wrapper functions that were being used in this driver. This also resolves a long-staging bug where data on the stack was being sent in a USB control message, which was not allowed. v2: API change of usb_control_msg_send() Cc: Jaroslav Kysela Reviewed-by: Takashi Iwai Link: https://lore.kernel.org/r/20200914153756.3412156-8-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- sound/usb/6fire/firmware.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/sound/usb/6fire/firmware.c b/sound/usb/6fire/firmware.c index 69137c14d0dc..8981e61f2da4 100644 --- a/sound/usb/6fire/firmware.c +++ b/sound/usb/6fire/firmware.c @@ -158,29 +158,17 @@ static int usb6fire_fw_ihex_init(const struct firmware *fw, static int usb6fire_fw_ezusb_write(struct usb_device *device, int type, int value, char *data, int len) { - int ret; - - ret = usb_control_msg(device, usb_sndctrlpipe(device, 0), type, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - value, 0, data, len, HZ); - if (ret < 0) - return ret; - else if (ret != len) - return -EIO; - return 0; + return usb_control_msg_send(device, 0, type, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + value, 0, data, len, HZ, GFP_KERNEL); } static int usb6fire_fw_ezusb_read(struct usb_device *device, int type, int value, char *data, int len) { - int ret = usb_control_msg(device, usb_rcvctrlpipe(device, 0), type, - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, value, - 0, data, len, HZ); - if (ret < 0) - return ret; - else if (ret != len) - return -EIO; - return 0; + return usb_control_msg_recv(device, 0, type, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + value, 0, data, len, HZ, GFP_KERNEL); } static int usb6fire_fw_fpga_write(struct usb_device *device, @@ -230,7 +218,7 @@ static int usb6fire_fw_ezusb_upload( /* upload firmware image */ data = 0x01; /* stop ezusb cpu */ ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1); - if (ret < 0) { + if (ret) { kfree(rec); release_firmware(fw); dev_err(&intf->dev, @@ -242,7 +230,7 @@ static int usb6fire_fw_ezusb_upload( while (usb6fire_fw_ihex_next_record(rec)) { /* write firmware */ ret = usb6fire_fw_ezusb_write(device, 0xa0, rec->address, rec->data, rec->len); - if (ret < 0) { + if (ret) { kfree(rec); release_firmware(fw); dev_err(&intf->dev, @@ -257,7 +245,7 @@ static int usb6fire_fw_ezusb_upload( if (postdata) { /* write data after firmware has been uploaded */ ret = usb6fire_fw_ezusb_write(device, 0xa0, postaddr, postdata, postlen); - if (ret < 0) { + if (ret) { dev_err(&intf->dev, "unable to upload ezusb firmware %s: post urb.\n", fwname); @@ -267,7 +255,7 @@ static int usb6fire_fw_ezusb_upload( data = 0x00; /* resume ezusb cpu */ ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1); - if (ret < 0) { + if (ret) { dev_err(&intf->dev, "unable to upload ezusb firmware %s: end message.\n", fwname); @@ -302,7 +290,7 @@ static int usb6fire_fw_fpga_upload( end = fw->data + fw->size; ret = usb6fire_fw_ezusb_write(device, 8, 0, NULL, 0); - if (ret < 0) { + if (ret) { kfree(buffer); release_firmware(fw); dev_err(&intf->dev, @@ -327,7 +315,7 @@ static int usb6fire_fw_fpga_upload( kfree(buffer); ret = usb6fire_fw_ezusb_write(device, 9, 0, NULL, 0); - if (ret < 0) { + if (ret) { dev_err(&intf->dev, "unable to upload fpga firmware: end urb.\n"); return ret; @@ -363,7 +351,7 @@ int usb6fire_fw_init(struct usb_interface *intf) u8 buffer[12]; ret = usb6fire_fw_ezusb_read(device, 1, 0, buffer, 8); - if (ret < 0) { + if (ret) { dev_err(&intf->dev, "unable to receive device firmware state.\n"); return ret; From patchwork Wed Sep 23 13:43:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 258439 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 F1286C4727F for ; Wed, 23 Sep 2020 13:44:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FA1521D92 for ; Wed, 23 Sep 2020 13:44:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qLTJBhWT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726550AbgIWNo2 (ORCPT ); Wed, 23 Sep 2020 09:44:28 -0400 Received: from mx2.suse.de ([195.135.220.15]:33516 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726652AbgIWNoU (ORCPT ); Wed, 23 Sep 2020 09:44:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=9gBWBURTzUv0WnRJZJxZd+G+ZLDTK1dLpxjaFBsX294=; b=qLTJBhWTRGwDnFwbz+uednDwW5l0+SlJxjecgGWX6GU0cXMDyuS1mQYh2t2WVac+bnXQe5 l9oIfbDvLSIjwasc1XU166Zuz26FyXwj2HunCO//yFWHvymPDfzCnNZRbdPd9lvkN+DUpt omI690ikToFWDvCUli/tYusSdozwycc= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3A0C7B1B1; Wed, 23 Sep 2020 13:44:55 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Juergen Stuber Subject: [RFC 11/14] USB: legousbtower: use usb_control_msg_recv() Date: Wed, 23 Sep 2020 15:43:45 +0200 Message-Id: <20200923134348.23862-12-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Greg Kroah-Hartman The usb_control_msg_recv() function can handle data on the stack, as well as properly detecting short reads, so move to use that function instead of the older usb_control_msg() call. This ends up removing a lot of extra lines in the driver. v2: change API of usb_control_msg_send() Cc: Juergen Stuber Link: https://lore.kernel.org/r/20200914153756.3412156-6-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/legousbtower.c | 61 ++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c index f922544056de..ba655b4af4fc 100644 --- a/drivers/usb/misc/legousbtower.c +++ b/drivers/usb/misc/legousbtower.c @@ -308,15 +308,9 @@ static int tower_open(struct inode *inode, struct file *file) int subminor; int retval = 0; struct usb_interface *interface; - struct tower_reset_reply *reset_reply; + struct tower_reset_reply reset_reply; int result; - reset_reply = kmalloc(sizeof(*reset_reply), GFP_KERNEL); - if (!reset_reply) { - retval = -ENOMEM; - goto exit; - } - nonseekable_open(inode, file); subminor = iminor(inode); @@ -347,15 +341,12 @@ static int tower_open(struct inode *inode, struct file *file) } /* reset the tower */ - result = usb_control_msg(dev->udev, - usb_rcvctrlpipe(dev->udev, 0), - LEGO_USB_TOWER_REQUEST_RESET, - USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE, - 0, - 0, - reset_reply, - sizeof(*reset_reply), - 1000); + result = usb_control_msg_recv(dev->udev, 0, + LEGO_USB_TOWER_REQUEST_RESET, + USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE, + 0, 0, + &reset_reply, sizeof(reset_reply), 1000, + GFP_KERNEL); if (result < 0) { dev_err(&dev->udev->dev, "LEGO USB Tower reset control request failed\n"); @@ -394,7 +385,6 @@ static int tower_open(struct inode *inode, struct file *file) mutex_unlock(&dev->lock); exit: - kfree(reset_reply); return retval; } @@ -753,7 +743,7 @@ static int tower_probe(struct usb_interface *interface, const struct usb_device_ struct device *idev = &interface->dev; struct usb_device *udev = interface_to_usbdev(interface); struct lego_usb_tower *dev; - struct tower_get_version_reply *get_version_reply = NULL; + struct tower_get_version_reply get_version_reply; int retval = -ENOMEM; int result; @@ -798,34 +788,25 @@ static int tower_probe(struct usb_interface *interface, const struct usb_device_ dev->interrupt_in_interval = interrupt_in_interval ? interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; dev->interrupt_out_interval = interrupt_out_interval ? interrupt_out_interval : dev->interrupt_out_endpoint->bInterval; - get_version_reply = kmalloc(sizeof(*get_version_reply), GFP_KERNEL); - if (!get_version_reply) { - retval = -ENOMEM; - goto error; - } - /* get the firmware version and log it */ - result = usb_control_msg(udev, - usb_rcvctrlpipe(udev, 0), - LEGO_USB_TOWER_REQUEST_GET_VERSION, - USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE, - 0, - 0, - get_version_reply, - sizeof(*get_version_reply), - 1000); - if (result != sizeof(*get_version_reply)) { - if (result >= 0) - result = -EIO; + result = usb_control_msg_recv(udev, 0, + LEGO_USB_TOWER_REQUEST_GET_VERSION, + USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE, + 0, + 0, + &get_version_reply, + sizeof(get_version_reply), + 1000, GFP_KERNEL); + if (!result) { dev_err(idev, "get version request failed: %d\n", result); retval = result; goto error; } dev_info(&interface->dev, "LEGO USB Tower firmware version is %d.%d build %d\n", - get_version_reply->major, - get_version_reply->minor, - le16_to_cpu(get_version_reply->build_no)); + get_version_reply.major, + get_version_reply.minor, + le16_to_cpu(get_version_reply.build_no)); /* we can register the device now, as it is ready */ usb_set_intfdata(interface, dev); @@ -844,11 +825,9 @@ static int tower_probe(struct usb_interface *interface, const struct usb_device_ USB_MAJOR, dev->minor); exit: - kfree(get_version_reply); return retval; error: - kfree(get_version_reply); tower_delete(dev); return retval; } From patchwork Wed Sep 23 13:43:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 297530 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 6D07EC2D0A8 for ; Wed, 23 Sep 2020 13:44:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 177C821D92 for ; Wed, 23 Sep 2020 13:44:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="esDU2k41" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726516AbgIWNoZ (ORCPT ); Wed, 23 Sep 2020 09:44:25 -0400 Received: from mx2.suse.de ([195.135.220.15]:33520 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726648AbgIWNoV (ORCPT ); Wed, 23 Sep 2020 09:44:21 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=A0SLqdQOgt7r1yxVF4MnON32ZU4vIOB9jRiWgTSt+L4=; b=esDU2k41bvxKjjzDDZsqXmy+Riu2rJ0TkOfRRs7gS1p0iNuJr5Nbchp164DX9Gfx3DxKCq K3R8d3qMGXd9ElYelsoSuvPbkN/TqLRlb/7+RSLlGAjIiRKQmrRD0tB8YAXNDvztl7yVIg VBLzUzoAdwFmYRE/j/YR2rJk2FzOOCw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7C833AD2C; Wed, 23 Sep 2020 13:44:55 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Jaroslav Kysela , Vasily Khoruzhick Subject: [RFC 12/14] sound: line6: move to use usb_control_msg_send() and usb_control_msg_recv() Date: Wed, 23 Sep 2020 15:43:46 +0200 Message-Id: <20200923134348.23862-13-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Greg Kroah-Hartman The usb_control_msg_send() and usb_control_msg_recv() calls can return an error if a "short" write/read happens, and they can handle data off of the stack, so move the driver over to using those calls instead, saving some logic when dynamically allocating memory. v2: API change of use usb_control_msg_send() and usb_control_msg_recv() Cc: Jaroslav Kysela Cc: Vasily Khoruzhick Reviewed-by: Takashi Iwai Link: https://lore.kernel.org/r/20200914153756.3412156-9-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- sound/usb/line6/driver.c | 72 +++++++++++++++++++--------------------------- sound/usb/line6/podhd.c | 23 ++++++--------- sound/usb/line6/toneport.c | 9 +++--- 3 files changed, 44 insertions(+), 60 deletions(-) diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c index 60674ce4879b..a030dd65eb28 100644 --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -337,23 +337,18 @@ int line6_read_data(struct usb_line6 *line6, unsigned address, void *data, { struct usb_device *usbdev = line6->usbdev; int ret; - unsigned char *len; + u8 len; unsigned count; if (address > 0xffff || datalen > 0xff) return -EINVAL; - len = kmalloc(1, GFP_KERNEL); - if (!len) - return -ENOMEM; - /* query the serial number: */ - ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, - (datalen << 8) | 0x21, address, - NULL, 0, LINE6_TIMEOUT * HZ); - - if (ret < 0) { + ret = usb_control_msg_send(usbdev, 0, 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, + (datalen << 8) | 0x21, address, NULL, 0, + LINE6_TIMEOUT * HZ, GFP_KERNEL); + if (ret) { dev_err(line6->ifcdev, "read request failed (error %d)\n", ret); goto exit; } @@ -362,45 +357,42 @@ int line6_read_data(struct usb_line6 *line6, unsigned address, void *data, for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) { mdelay(LINE6_READ_WRITE_STATUS_DELAY); - ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | - USB_DIR_IN, - 0x0012, 0x0000, len, 1, - LINE6_TIMEOUT * HZ); - if (ret < 0) { + ret = usb_control_msg_recv(usbdev, 0, 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, + 0x0012, 0x0000, &len, 1, + LINE6_TIMEOUT * HZ, GFP_KERNEL); + if (ret) { dev_err(line6->ifcdev, "receive length failed (error %d)\n", ret); goto exit; } - if (*len != 0xff) + if (len != 0xff) break; } ret = -EIO; - if (*len == 0xff) { + if (len == 0xff) { dev_err(line6->ifcdev, "read failed after %d retries\n", count); goto exit; - } else if (*len != datalen) { + } else if (len != datalen) { /* should be equal or something went wrong */ dev_err(line6->ifcdev, "length mismatch (expected %d, got %d)\n", - (int)datalen, (int)*len); + (int)datalen, len); goto exit; } /* receive the result: */ - ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, - 0x0013, 0x0000, data, datalen, - LINE6_TIMEOUT * HZ); - - if (ret < 0) + ret = usb_control_msg_recv(usbdev, 0, 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, + 0x0013, 0x0000, data, datalen, LINE6_TIMEOUT * HZ, + GFP_KERNEL); + if (ret) dev_err(line6->ifcdev, "read failed (error %d)\n", ret); exit: - kfree(len); return ret; } EXPORT_SYMBOL_GPL(line6_read_data); @@ -423,12 +415,11 @@ int line6_write_data(struct usb_line6 *line6, unsigned address, void *data, if (!status) return -ENOMEM; - ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, - 0x0022, address, data, datalen, - LINE6_TIMEOUT * HZ); - - if (ret < 0) { + ret = usb_control_msg_send(usbdev, 0, 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, + 0x0022, address, data, datalen, LINE6_TIMEOUT * HZ, + GFP_KERNEL); + if (ret) { dev_err(line6->ifcdev, "write request failed (error %d)\n", ret); goto exit; @@ -437,14 +428,11 @@ int line6_write_data(struct usb_line6 *line6, unsigned address, void *data, for (count = 0; count < LINE6_READ_WRITE_MAX_RETRIES; count++) { mdelay(LINE6_READ_WRITE_STATUS_DELAY); - ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), - 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | - USB_DIR_IN, - 0x0012, 0x0000, - status, 1, LINE6_TIMEOUT * HZ); - - if (ret < 0) { + ret = usb_control_msg_recv(usbdev, 0, 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, + 0x0012, 0x0000, status, 1, LINE6_TIMEOUT * HZ, + GFP_KERNEL); + if (ret) { dev_err(line6->ifcdev, "receiving status failed (error %d)\n", ret); goto exit; diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c index eef45f7fef0d..28794a35949d 100644 --- a/sound/usb/line6/podhd.c +++ b/sound/usb/line6/podhd.c @@ -183,29 +183,25 @@ static const struct attribute_group podhd_dev_attr_group = { static int podhd_dev_start(struct usb_line6_podhd *pod) { int ret; - u8 *init_bytes; + u8 init_bytes[8]; int i; struct usb_device *usbdev = pod->line6.usbdev; - init_bytes = kmalloc(8, GFP_KERNEL); - if (!init_bytes) - return -ENOMEM; - - ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), + ret = usb_control_msg_send(usbdev, 0, 0x67, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, 0x11, 0, - NULL, 0, LINE6_TIMEOUT * HZ); - if (ret < 0) { + NULL, 0, LINE6_TIMEOUT * HZ, GFP_KERNEL); + if (ret) { dev_err(pod->line6.ifcdev, "read request failed (error %d)\n", ret); goto exit; } /* NOTE: looks like some kind of ping message */ - ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, + ret = usb_control_msg_recv(usbdev, 0, 0x67, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 0x11, 0x0, - init_bytes, 3, LINE6_TIMEOUT * HZ); - if (ret < 0) { + init_bytes, 3, LINE6_TIMEOUT * HZ, GFP_KERNEL); + if (ret) { dev_err(pod->line6.ifcdev, "receive length failed (error %d)\n", ret); goto exit; @@ -220,13 +216,12 @@ static int podhd_dev_start(struct usb_line6_podhd *pod) goto exit; } - ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), + ret = usb_control_msg_send(usbdev, 0, USB_REQ_SET_FEATURE, USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_DIR_OUT, 1, 0, - NULL, 0, LINE6_TIMEOUT * HZ); + NULL, 0, LINE6_TIMEOUT * HZ, GFP_KERNEL); exit: - kfree(init_bytes); return ret; } diff --git a/sound/usb/line6/toneport.c b/sound/usb/line6/toneport.c index 94dd5e7ab2e6..4e5693c97aa4 100644 --- a/sound/usb/line6/toneport.c +++ b/sound/usb/line6/toneport.c @@ -126,11 +126,12 @@ static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2) { int ret; - ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, - cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ); + ret = usb_control_msg_send(usbdev, 0, 0x67, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, + cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ, + GFP_KERNEL); - if (ret < 0) { + if (ret) { dev_err(&usbdev->dev, "send failed (error %d)\n", ret); return ret; } From patchwork Wed Sep 23 13:43:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 297531 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 86774C2D0A8 for ; Wed, 23 Sep 2020 13:44:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FF9A21D92 for ; Wed, 23 Sep 2020 13:44:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="C0f4Huxo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbgIWNoX (ORCPT ); Wed, 23 Sep 2020 09:44:23 -0400 Received: from mx2.suse.de ([195.135.220.15]:33568 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726662AbgIWNoU (ORCPT ); Wed, 23 Sep 2020 09:44:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=J8kb2Y6xVaUgs3fR1w109xfB+LPi5dm748aQ+V80RFQ=; b=C0f4HuxoJGjDTusjunJxM43U+Mb5MGuZvObd4nVGyLiCCN0kqn4x3Zn781VrdoQxk2FnHo gYUSQ9lW95TKHb/2648cYbbo1/4FuwGQUbeB0stf62cNqDVCyV0kBsWDrYdS61fEakfY4C h/buFd6zpDSEHax74R08lDZlYFyfaq4= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B2569AD57; Wed, 23 Sep 2020 13:44:55 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Jaroslav Kysela Subject: [RFC 13/14] sound: hiface: move to use usb_control_msg_send() Date: Wed, 23 Sep 2020 15:43:47 +0200 Message-Id: <20200923134348.23862-14-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Greg Kroah-Hartman The usb_control_msg_send() call can return an error if a "short" write happens, so move the driver over to using that call instead. v2: API change of use usb_control_msg_send() Cc: Jaroslav Kysela Reviewed-by: Takashi Iwai Link: https://lore.kernel.org/r/20200914153756.3412156-10-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- sound/usb/hiface/pcm.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sound/usb/hiface/pcm.c b/sound/usb/hiface/pcm.c index a148caa5f48e..d942179ca095 100644 --- a/sound/usb/hiface/pcm.c +++ b/sound/usb/hiface/pcm.c @@ -156,16 +156,14 @@ static int hiface_pcm_set_rate(struct pcm_runtime *rt, unsigned int rate) * This control message doesn't have any ack from the * other side */ - ret = usb_control_msg(device, usb_sndctrlpipe(device, 0), - HIFACE_SET_RATE_REQUEST, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, - rate_value, 0, NULL, 0, 100); - if (ret < 0) { + ret = usb_control_msg_send(device, 0, + HIFACE_SET_RATE_REQUEST, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, + rate_value, 0, NULL, 0, 100, GFP_KERNEL); + if (ret) dev_err(&device->dev, "Error setting samplerate %d.\n", rate); - return ret; - } - return 0; + return ret; } static struct pcm_substream *hiface_pcm_get_substream(struct snd_pcm_substream From patchwork Wed Sep 23 13:43:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 258441 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 0089DC4727F for ; Wed, 23 Sep 2020 13:44:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9201E221EB for ; Wed, 23 Sep 2020 13:44:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="cU22vL/X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726676AbgIWNoX (ORCPT ); Wed, 23 Sep 2020 09:44:23 -0400 Received: from mx2.suse.de ([195.135.220.15]:33570 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726665AbgIWNoV (ORCPT ); Wed, 23 Sep 2020 09:44:21 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600868658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=yCv7WrZYb36PkOKNs7Oi8LaBe0UGsPc0LZvsDneuTrk=; b=cU22vL/X68Oa+VDQljgW/rqUvh+/xB02xswZaSpuYCvpsk2nnaU8fDtSWHSUXstSXslwP+ pAl2KhiS8aq/jVoM6U7EnEl0wEhjitNS5wUw6JcomOn/93OUB5KMDK+PuuRV+6AWyTTkBT FITsjiGLqavWUhAJ9uB6g0dutQmjRlE= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 09617ADBB; Wed, 23 Sep 2020 13:44:56 +0000 (UTC) From: Oliver Neukum To: himadrispandya@gmail.com, gregKH@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Marcel Holtmann , Johan Hedberg Subject: [RFC 14/14] Bluetooth: ath3k: use usb_control_msg_send() and usb_control_msg_recv() Date: Wed, 23 Sep 2020 15:43:48 +0200 Message-Id: <20200923134348.23862-15-oneukum@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200923134348.23862-1-oneukum@suse.com> References: <20200923134348.23862-1-oneukum@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Greg Kroah-Hartman The usb_control_msg_send() and usb_control_msg_recv() calls can return an error if a "short" write/read happens, and they can handle data off of the stack, so move the driver over to using those calls instead, saving some logic when dynamically allocating memory. v2: changed API of use usb_control_msg_send() and usb_control_msg_recv() Cc: Marcel Holtmann Cc: Johan Hedberg Link: https://lore.kernel.org/r/20200914153756.3412156-11-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/bluetooth/ath3k.c | 93 +++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 64 deletions(-) diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c index 4ce270513695..759d7828931d 100644 --- a/drivers/bluetooth/ath3k.c +++ b/drivers/bluetooth/ath3k.c @@ -212,19 +212,16 @@ static int ath3k_load_firmware(struct usb_device *udev, BT_DBG("udev %p", udev); - pipe = usb_sndctrlpipe(udev, 0); - send_buf = kmalloc(BULK_SIZE, GFP_KERNEL); if (!send_buf) { BT_ERR("Can't allocate memory chunk for firmware"); return -ENOMEM; } - memcpy(send_buf, firmware->data, FW_HDR_SIZE); - err = usb_control_msg(udev, pipe, USB_REQ_DFU_DNLOAD, USB_TYPE_VENDOR, - 0, 0, send_buf, FW_HDR_SIZE, - USB_CTRL_SET_TIMEOUT); - if (err < 0) { + err = usb_control_msg_send(udev, 0, USB_REQ_DFU_DNLOAD, USB_TYPE_VENDOR, + 0, 0, firmware->data, FW_HDR_SIZE, + USB_CTRL_SET_TIMEOUT, GFP_KERNEL); + if (err) { BT_ERR("Can't change to loading configuration err"); goto error; } @@ -259,44 +256,19 @@ static int ath3k_load_firmware(struct usb_device *udev, static int ath3k_get_state(struct usb_device *udev, unsigned char *state) { - int ret, pipe = 0; - char *buf; - - buf = kmalloc(sizeof(*buf), GFP_KERNEL); - if (!buf) - return -ENOMEM; - - pipe = usb_rcvctrlpipe(udev, 0); - ret = usb_control_msg(udev, pipe, ATH3K_GETSTATE, - USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, - buf, sizeof(*buf), USB_CTRL_SET_TIMEOUT); - - *state = *buf; - kfree(buf); - - return ret; + return usb_control_msg_recv(udev, 0, ATH3K_GETSTATE, + USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, + state, 1, USB_CTRL_SET_TIMEOUT, + GFP_KERNEL); } static int ath3k_get_version(struct usb_device *udev, struct ath3k_version *version) { - int ret, pipe = 0; - struct ath3k_version *buf; - const int size = sizeof(*buf); - - buf = kmalloc(size, GFP_KERNEL); - if (!buf) - return -ENOMEM; - - pipe = usb_rcvctrlpipe(udev, 0); - ret = usb_control_msg(udev, pipe, ATH3K_GETVERSION, - USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, - buf, size, USB_CTRL_SET_TIMEOUT); - - memcpy(version, buf, size); - kfree(buf); - - return ret; + return usb_control_msg_recv(udev, 0, ATH3K_GETVERSION, + USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, + version, sizeof(*version), USB_CTRL_SET_TIMEOUT, + GFP_KERNEL); } static int ath3k_load_fwfile(struct usb_device *udev, @@ -316,13 +288,11 @@ static int ath3k_load_fwfile(struct usb_device *udev, } size = min_t(uint, count, FW_HDR_SIZE); - memcpy(send_buf, firmware->data, size); - pipe = usb_sndctrlpipe(udev, 0); - ret = usb_control_msg(udev, pipe, ATH3K_DNLOAD, - USB_TYPE_VENDOR, 0, 0, send_buf, - size, USB_CTRL_SET_TIMEOUT); - if (ret < 0) { + ret = usb_control_msg_send(udev, 0, ATH3K_DNLOAD, USB_TYPE_VENDOR, 0, 0, + firmware->data, size, USB_CTRL_SET_TIMEOUT, + GFP_KERNEL); + if (ret) { BT_ERR("Can't change to loading configuration err"); kfree(send_buf); return ret; @@ -355,23 +325,19 @@ static int ath3k_load_fwfile(struct usb_device *udev, return 0; } -static int ath3k_switch_pid(struct usb_device *udev) +static void ath3k_switch_pid(struct usb_device *udev) { - int pipe = 0; - - pipe = usb_sndctrlpipe(udev, 0); - return usb_control_msg(udev, pipe, USB_REG_SWITCH_VID_PID, - USB_TYPE_VENDOR, 0, 0, - NULL, 0, USB_CTRL_SET_TIMEOUT); + usb_control_msg_send(udev, 0, USB_REG_SWITCH_VID_PID, USB_TYPE_VENDOR, + 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT, GFP_KERNEL); } static int ath3k_set_normal_mode(struct usb_device *udev) { unsigned char fw_state; - int pipe = 0, ret; + int ret; ret = ath3k_get_state(udev, &fw_state); - if (ret < 0) { + if (ret) { BT_ERR("Can't get state to change to normal mode err"); return ret; } @@ -381,10 +347,9 @@ static int ath3k_set_normal_mode(struct usb_device *udev) return 0; } - pipe = usb_sndctrlpipe(udev, 0); - return usb_control_msg(udev, pipe, ATH3K_SET_NORMAL_MODE, - USB_TYPE_VENDOR, 0, 0, - NULL, 0, USB_CTRL_SET_TIMEOUT); + return usb_control_msg_send(udev, 0, ATH3K_SET_NORMAL_MODE, + USB_TYPE_VENDOR, 0, 0, NULL, 0, + USB_CTRL_SET_TIMEOUT, GFP_KERNEL); } static int ath3k_load_patch(struct usb_device *udev) @@ -397,7 +362,7 @@ static int ath3k_load_patch(struct usb_device *udev) int ret; ret = ath3k_get_state(udev, &fw_state); - if (ret < 0) { + if (ret) { BT_ERR("Can't get state to change to load ram patch err"); return ret; } @@ -408,7 +373,7 @@ static int ath3k_load_patch(struct usb_device *udev) } ret = ath3k_get_version(udev, &fw_version); - if (ret < 0) { + if (ret) { BT_ERR("Can't get version to change to load ram patch err"); return ret; } @@ -449,13 +414,13 @@ static int ath3k_load_syscfg(struct usb_device *udev) int clk_value, ret; ret = ath3k_get_state(udev, &fw_state); - if (ret < 0) { + if (ret) { BT_ERR("Can't get state to change to load configuration err"); return -EBUSY; } ret = ath3k_get_version(udev, &fw_version); - if (ret < 0) { + if (ret) { BT_ERR("Can't get version to change to load ram patch err"); return ret; } @@ -529,7 +494,7 @@ static int ath3k_probe(struct usb_interface *intf, return ret; } ret = ath3k_set_normal_mode(udev); - if (ret < 0) { + if (ret) { BT_ERR("Set normal mode failed"); return ret; }