From patchwork Tue Jan 26 18:33:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12050027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35ED1C433DB for ; Wed, 27 Jan 2021 12:47:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED592207B1 for ; Wed, 27 Jan 2021 12:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S313986AbhAZWxn (ORCPT ); Tue, 26 Jan 2021 17:53:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392183AbhAZSfQ (ORCPT ); Tue, 26 Jan 2021 13:35:16 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B939C061574; Tue, 26 Jan 2021 10:34:36 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id w18so10934662pfu.9; Tue, 26 Jan 2021 10:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cBTsPIheAREODwP7ehxYmG/rqbt0+8mgZWOAMNTxbTk=; b=FLafbb7XTRsKX1L715KcNJg+CKnrIAYDl4z0BCWsEL3BAed2CJrMAruBQHkjGdf9Hd JRiDavYtVe2Xen/sfUfAb5EK1/Kh5muVC8EY3FrjO0qfLfkmV8fwOKa2lM1cFbu+RmhT B9mNEybzMhPOTuMRk79VmW3MAnTZBoTzofVgNTAagqvp4yRssiYV4+BMTAip7lWbXwAG 1IICIxLMSxv7ZfmOjbdceUTVDTJ2DFW9BAYPeY4eoFu4Ed5fFvrUXXCL8Y05XqQ9ZkAy HSGtojL/GP311Xu+FUv06mzVIdghRzMpjf44DA7xEMgBlj5lACdyKIV3oKAet03DGqfg HNsg== 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=cBTsPIheAREODwP7ehxYmG/rqbt0+8mgZWOAMNTxbTk=; b=jdugLVhsXtCCg+FFavyuV2bXEGQPE7MzJZnAbgfTV6wAwaPkHiu3BlhwNerBYms/4V GyEu6YpthvRQ0VuTmFHNBGgILPguo+eQNmYvgxTZgvBnXhWsNxZBzRcan8ovAcy/Al2t xZFDy3Uh3Ebqwo6tTO1RBbLcikLIxmkwAkfnvr6qcYVdCq2sOsPn2rfvX3887oDVCgAs GCko836Sj1Kq5qf/QjuwXOoi27q7BpOKv8uUHX/NM7/BbpPzXB1usw47ILV7SnHxKjXB Y3E6LyOwgM9PT4Tzvxfn9dbd4Ka8m4OY9FdOBAXk9AvxZkQN5tBPVC04uztruphI6dWW 5rOg== X-Gm-Message-State: AOAM531uSVZX9mNB+uiOeK2Tqj/ytGcC/IYH1nt4hCexH3FhlXQl6Rtr 1s9EwJzA3AySDVPqP7Q61ITfknDF0azM5V9g+ig= X-Google-Smtp-Source: ABdhPJx+KcEI8M10QX5h8Tn2JGd06zfMciGCORZutfxv+gahx/R8EXxq3UQTRvIhfCtDKIMy4CLBaQ== X-Received: by 2002:a63:4443:: with SMTP id t3mr6947500pgk.297.1611686075647; Tue, 26 Jan 2021 10:34:35 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id y75sm472711pfg.119.2021.01.26.10.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:34:34 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , "Gustavo A. R. Silva" , Xu Wang , Liu Shixin , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 01/12] usb: misc: appledisplay: update to use the usb_control_msg_{send|recv}() API Date: Wed, 27 Jan 2021 00:03:52 +0530 Message-Id: <20210126183403.911653-2-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, instances of usb_control_msg() have been replaced with usb_control_msg_{recv|send}(), and all return value checking conditions have also been modified appropriately. Signed-off-by: Anant Thazhemadam --- drivers/usb/misc/appledisplay.c | 46 ++++++++++++++------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c index c8098e9b432e..117deb2fdc29 100644 --- a/drivers/usb/misc/appledisplay.c +++ b/drivers/usb/misc/appledisplay.c @@ -132,21 +132,17 @@ static int appledisplay_bl_update_status(struct backlight_device *bd) pdata->msgdata[0] = 0x10; pdata->msgdata[1] = bd->props.brightness; - retval = usb_control_msg( - pdata->udev, - usb_sndctrlpipe(pdata->udev, 0), - USB_REQ_SET_REPORT, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - ACD_USB_BRIGHTNESS, - 0, - pdata->msgdata, 2, - ACD_USB_TIMEOUT); + retval = usb_control_msg_send(pdata->udev, + 0, + USB_REQ_SET_REPORT, + USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, + ACD_USB_BRIGHTNESS, + 0, + pdata->msgdata, 2, + ACD_USB_TIMEOUT, GFP_KERNEL); mutex_unlock(&pdata->sysfslock); - if (retval < 0) - return retval; - else - return 0; + return retval; } static int appledisplay_bl_get_brightness(struct backlight_device *bd) @@ -155,21 +151,17 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd) int retval, brightness; mutex_lock(&pdata->sysfslock); - retval = usb_control_msg( - pdata->udev, - usb_rcvctrlpipe(pdata->udev, 0), - USB_REQ_GET_REPORT, - USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - ACD_USB_BRIGHTNESS, - 0, - pdata->msgdata, 2, - ACD_USB_TIMEOUT); - if (retval < 2) { - if (retval >= 0) - retval = -EMSGSIZE; - } else { + retval = usb_control_msg_recv(pdata->udev, + 0, + USB_REQ_GET_REPORT, + USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, + ACD_USB_BRIGHTNESS, + 0, + pdata->msgdata, 2, + ACD_USB_TIMEOUT, GFP_KERNEL); + if (retval == 0) brightness = pdata->msgdata[1]; - } + mutex_unlock(&pdata->sysfslock); if (retval < 0) From patchwork Tue Jan 26 18:33:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12048555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD206C433DB for ; Tue, 26 Jan 2021 22:54:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 994082065E for ; Tue, 26 Jan 2021 22:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727774AbhAZWyA (ORCPT ); Tue, 26 Jan 2021 17:54:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394767AbhAZSfi (ORCPT ); Tue, 26 Jan 2021 13:35:38 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E250AC061756; Tue, 26 Jan 2021 10:34:57 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id q2so7484423plk.4; Tue, 26 Jan 2021 10:34:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OR9wVz2vxGr4uGs0aRUSPWq5Qs/Y5o7RNeRWhP0NrZ0=; b=bx7/Of/QgmIIlJDhv2cIBDHcAMgF2psnNmkAvZ6KbKf80bcchoKgJX3ZDVUNhf5w3r ZSGqDJh2MBJo0oc9E54zWqgaYh8qFRHXV9kSe7uts1BOck7A+8/oWE+vLvH2f1Gvupo6 SYOamguevR5Gp3w2Utkivq8XP24pIM3+tQib/1JERwyfbfwda8KjARJoLiAw0qgZUptT EL5H2QSsrn03tgP/YvO3q6ae/NEDMGVuOlj1fB+CvZVTOTjy9BOuVNy654DmlrAXB7yS VN/WA+/DsX47GvvlTWG8xt19RJ0BSxBjLSIVm5W3xBFu4bTxuUuwKWAwFMGAh0/W+BXY fUIQ== 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=OR9wVz2vxGr4uGs0aRUSPWq5Qs/Y5o7RNeRWhP0NrZ0=; b=CsiXiJUKp+yM7m3lZvKUI4Z31i5D6tLr/4iVXwk43UqSqR1MtoMXmsGm8VE5yXvJW4 TXgqJEyHQvHpfAlhKMx6FbVInbOZw3ZPvNl0/7iB1RZWF8TsNJUu3/Of59+DYBJJZiHQ tMjzzljbp9v2/ixFtRvyYJFnQfpkq3/OfKQP3JFn5FFHy6M9XqMKmyYmmexSkotsRS8M 3gsO1LyfN7dHt+rwUt503oga6BYZk+A6Ty3hDja3vv51DDFxWv7poj8AZy+BW0Jh2eKV S0x0PIA5U3709BkIGSBdGkWS8GTPjMY33Elp5KUEpe9pN8NKsdg/+SLb4FCQB+9NDCpE 9oiw== X-Gm-Message-State: AOAM530Gx2eaDRUEtCxUAd3FjdBGF+UvcEHXbsyFiUssHltagierPIdH 0O798ueAQxqnQSxaXoGNC3uhU/rwPUw/0eZVMOw= X-Google-Smtp-Source: ABdhPJwigx9Ufx12ORwvqE9EwFeEjggnfZabvy73Op19avx0lbykcm49Yndao87OO0FjgGbMT5/2CQ== X-Received: by 2002:a17:90a:a508:: with SMTP id a8mr1146415pjq.75.1611686097307; Tue, 26 Jan 2021 10:34:57 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id y75sm472711pfg.119.2021.01.26.10.34.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:34:56 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 02/12] usb: misc: cypress_cy7c63: update to use usb_control_msg_recv() Date: Wed, 27 Jan 2021 00:03:53 +0530 Message-Id: <20210126183403.911653-3-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, the instance of usb_control_msg() has been replaced with usb_control_msg_recv(). Signed-off-by: Anant Thazhemadam --- drivers/usb/misc/cypress_cy7c63.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c index 14faec51d7a5..76a320ef17a7 100644 --- a/drivers/usb/misc/cypress_cy7c63.c +++ b/drivers/usb/misc/cypress_cy7c63.c @@ -70,24 +70,15 @@ static int vendor_command(struct cypress *dev, unsigned char request, unsigned char address, unsigned char data) { int retval = 0; - unsigned int pipe; - unsigned char *iobuf; - - /* allocate some memory for the i/o buffer*/ - iobuf = kzalloc(CYPRESS_MAX_REQSIZE, GFP_KERNEL); - if (!iobuf) { - retval = -ENOMEM; - goto error; - } + u8 iobuf[CYPRESS_MAX_REQSIZE] = {0}; dev_dbg(&dev->udev->dev, "Sending usb_control_msg (data: %d)\n", data); /* prepare usb control message and send it upstream */ - pipe = usb_rcvctrlpipe(dev->udev, 0); - retval = usb_control_msg(dev->udev, pipe, request, - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, - address, data, iobuf, CYPRESS_MAX_REQSIZE, - USB_CTRL_GET_TIMEOUT); + retval = usb_control_msg_recv(dev->udev, 0, request, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, + address, data, &iobuf, CYPRESS_MAX_REQSIZE, + USB_CTRL_GET_TIMEOUT, GFP_KERNEL); /* store returned data (more READs to be added) */ switch (request) { @@ -107,8 +98,6 @@ static int vendor_command(struct cypress *dev, unsigned char request, break; } - kfree(iobuf); -error: return retval; } From patchwork Tue Jan 26 18:33:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12048557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB660C433E0 for ; Tue, 26 Jan 2021 22:54:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B93662067B for ; Tue, 26 Jan 2021 22:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725320AbhAZWyM (ORCPT ); Tue, 26 Jan 2021 17:54:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394775AbhAZSfm (ORCPT ); Tue, 26 Jan 2021 13:35:42 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 414A3C0613D6; Tue, 26 Jan 2021 10:35:02 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id g15so2754036pjd.2; Tue, 26 Jan 2021 10:35:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6xBjojemrIICF/vl8V5tDr3Zp6uDLBqRICYfScnuO8M=; b=iruQUIgQiNgJrLRO9/EBb3aqH5y6+bSnQbUFW3wyjWa4lSEi++Y2ZDT2nqXgPJVzHe 8Pb1mDxiD3J2VJxL46JPGIeQrDPHBckHM8Ax7IQRLuOFO84QZzGWHbr+LVy0pYoGHcvH b/sFebwHyZW44POLqm4selzpRdsmw3+QqLS2tUXMMBCIPM46P36W85mGAlB8yCQnN56A FGW71RLo6+Z+JgJXU4qSeAVMEH4ZNDqq+j5G2Sr4znexaU1MS3MGPDd50iHoCLMhySai VWzCQJIcrsYkdj/y1QCTY9Qi2wmfsHZ6ot8FDqx7s75vwqBC4S0WvVQ+sHmZPRfcJi1m vQmQ== 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=6xBjojemrIICF/vl8V5tDr3Zp6uDLBqRICYfScnuO8M=; b=WA9YalZb/lYlMoLvciPlhGp4mPZSFyd/Q13OGz4AKcobIh5XoXKgschIHwygUxi8Yb 7uih2gTOYVeqpBFcPTACt0Nqg5CDXND08k1Inri28LLaFs9Yum5/ePX8oFz4NO38FEjS 7sSHtrelHwSpGil59gL3yWzHLWztU6ZSuS/pUPogVFIF6wrB8c3/dbGhyJmOF9C2/RVM VIyQAgfrXni7gJ6VHJBJOdC0S2JVKTkl8jH2TDGc8WoFAdks1lZ9igkXCUw5Knb9Pll6 iTDMVh2dC121ihG3+Qp2XygB3EN9MhoJZDOyromALgrrXnWFdYVkBOVPdWy2aMtRV2QA OUrQ== X-Gm-Message-State: AOAM533lQjKF/vbNvBIkByPwF/u/VkUAfeXJ4aob1KQ88HJhCO+F5n51 c71dX3wSGvTWOwmG8I2nFCg= X-Google-Smtp-Source: ABdhPJyAlS3QOBvfItT197fMR9Vyp0UPTGYb6PrNqASrRoR4ARWHSy+ZqpF/uruk/NwnkG0SB6FlaQ== X-Received: by 2002:a17:90a:ab8e:: with SMTP id n14mr1130385pjq.96.1611686101757; Tue, 26 Jan 2021 10:35:01 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id y75sm472711pfg.119.2021.01.26.10.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:35:01 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 03/12] usb: misc: cytherm: update to use usb_control_msg_recv() Date: Wed, 27 Jan 2021 00:03:54 +0530 Message-Id: <20210126183403.911653-4-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, the instance of usb_control_msg() has been replaced with usb_control_msg_recv(). The return value checking enforced by callers of the updated function have also been appropriately updated. Signed-off-by: Anant Thazhemadam --- drivers/usb/misc/cytherm.c | 128 +++++++++++++------------------------ 1 file changed, 43 insertions(+), 85 deletions(-) diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c index 3e3802aaefa3..2ca36ea5b76a 100644 --- a/drivers/usb/misc/cytherm.c +++ b/drivers/usb/misc/cytherm.c @@ -51,12 +51,12 @@ static int vendor_command(struct usb_device *dev, unsigned char request, unsigned char value, unsigned char index, void *buf, int size) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - request, - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, - value, - index, buf, size, - USB_CTRL_GET_TIMEOUT); + return usb_control_msg_recv(dev, 0, + request, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, + value, + index, buf, size, + USB_CTRL_GET_TIMEOUT, GFP_KERNEL); } @@ -78,33 +78,27 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *att struct usb_interface *intf = to_usb_interface(dev); struct usb_cytherm *cytherm = usb_get_intfdata(intf); - unsigned char *buffer; + unsigned char buffer[8]; int retval; - - buffer = kmalloc(8, GFP_KERNEL); - if (!buffer) - return 0; cytherm->brightness = simple_strtoul(buf, NULL, 10); - + if (cytherm->brightness > 0xFF) cytherm->brightness = 0xFF; else if (cytherm->brightness < 0) cytherm->brightness = 0; - + /* Set brightness */ retval = vendor_command(cytherm->udev, WRITE_RAM, BRIGHTNESS, - cytherm->brightness, buffer, 8); - if (retval) - dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); + cytherm->brightness, &buffer, 8); + if (!retval) + dev_dbg(&cytherm->udev->dev, "brightness set correctly\n"); /* Inform µC that we have changed the brightness setting */ retval = vendor_command(cytherm->udev, WRITE_RAM, BRIGHTNESS_SEM, - 0x01, buffer, 8); - if (retval) - dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); - - kfree(buffer); - + 0x01, &buffer, 8); + if (!retval) + dev_dbg(&cytherm->udev->dev, "µC informed of change in brightness setting\n"); + return count; } static DEVICE_ATTR_RW(brightness); @@ -120,28 +114,22 @@ static ssize_t temp_show(struct device *dev, struct device_attribute *attr, char struct usb_cytherm *cytherm = usb_get_intfdata(intf); int retval; - unsigned char *buffer; + unsigned char buffer[8]; int temp, sign; - buffer = kmalloc(8, GFP_KERNEL); - if (!buffer) - return 0; - /* read temperature */ - retval = vendor_command(cytherm->udev, READ_RAM, TEMP, 0, buffer, 8); - if (retval) - dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); + retval = vendor_command(cytherm->udev, READ_RAM, TEMP, 0, &buffer, 8); + if (!retval) + dev_dbg(&cytherm->udev->dev, "read temperature successfully\n"); temp = buffer[1]; /* read sign */ - retval = vendor_command(cytherm->udev, READ_RAM, SIGN, 0, buffer, 8); - if (retval) - dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); + retval = vendor_command(cytherm->udev, READ_RAM, SIGN, 0, &buffer, 8); + if (!retval) + dev_dbg(&cytherm->udev->dev, "read sign successfully\n"); sign = buffer[1]; - kfree(buffer); - return sprintf(buf, "%c%i.%i", sign ? '-' : '+', temp >> 1, 5*(temp - ((temp >> 1) << 1))); } @@ -157,21 +145,15 @@ static ssize_t button_show(struct device *dev, struct device_attribute *attr, ch struct usb_cytherm *cytherm = usb_get_intfdata(intf); int retval; - unsigned char *buffer; - - buffer = kmalloc(8, GFP_KERNEL); - if (!buffer) - return 0; + unsigned char buffer[8]; /* check button */ - retval = vendor_command(cytherm->udev, READ_RAM, BUTTON, 0, buffer, 8); - if (retval) - dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); + retval = vendor_command(cytherm->udev, READ_RAM, BUTTON, 0, &buffer, 8); + if (!retval) + dev_dbg(&cytherm->udev->dev, "checked button successfully\n"); retval = buffer[1]; - kfree(buffer); - if (retval) return sprintf(buf, "1"); else @@ -186,20 +168,14 @@ static ssize_t port0_show(struct device *dev, struct device_attribute *attr, cha struct usb_cytherm *cytherm = usb_get_intfdata(intf); int retval; - unsigned char *buffer; - - buffer = kmalloc(8, GFP_KERNEL); - if (!buffer) - return 0; + unsigned char buffer[8]; - retval = vendor_command(cytherm->udev, READ_PORT, 0, 0, buffer, 8); - if (retval) + retval = vendor_command(cytherm->udev, READ_PORT, 0, 0, &buffer, 8); + if (!retval) dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); retval = buffer[1]; - kfree(buffer); - return sprintf(buf, "%d", retval); } @@ -209,28 +185,22 @@ static ssize_t port0_store(struct device *dev, struct device_attribute *attr, co struct usb_interface *intf = to_usb_interface(dev); struct usb_cytherm *cytherm = usb_get_intfdata(intf); - unsigned char *buffer; + unsigned char buffer[8]; int retval; int tmp; - - buffer = kmalloc(8, GFP_KERNEL); - if (!buffer) - return 0; tmp = simple_strtoul(buf, NULL, 10); - + if (tmp > 0xFF) tmp = 0xFF; else if (tmp < 0) tmp = 0; - + retval = vendor_command(cytherm->udev, WRITE_PORT, 0, - tmp, buffer, 8); - if (retval) + tmp, &buffer, 8); + if (!retval) dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); - kfree(buffer); - return count; } static DEVICE_ATTR_RW(port0); @@ -241,19 +211,13 @@ static ssize_t port1_show(struct device *dev, struct device_attribute *attr, cha struct usb_cytherm *cytherm = usb_get_intfdata(intf); int retval; - unsigned char *buffer; + unsigned char buffer[8]; - buffer = kmalloc(8, GFP_KERNEL); - if (!buffer) - return 0; - - retval = vendor_command(cytherm->udev, READ_PORT, 1, 0, buffer, 8); - if (retval) + retval = vendor_command(cytherm->udev, READ_PORT, 1, 0, &buffer, 8); + if (!retval) dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); - - retval = buffer[1]; - kfree(buffer); + retval = buffer[1]; return sprintf(buf, "%d", retval); } @@ -264,13 +228,9 @@ static ssize_t port1_store(struct device *dev, struct device_attribute *attr, co struct usb_interface *intf = to_usb_interface(dev); struct usb_cytherm *cytherm = usb_get_intfdata(intf); - unsigned char *buffer; + unsigned char buffer[8]; int retval; int tmp; - - buffer = kmalloc(8, GFP_KERNEL); - if (!buffer) - return 0; tmp = simple_strtoul(buf, NULL, 10); @@ -278,14 +238,12 @@ static ssize_t port1_store(struct device *dev, struct device_attribute *attr, co tmp = 0xFF; else if (tmp < 0) tmp = 0; - + retval = vendor_command(cytherm->udev, WRITE_PORT, 1, - tmp, buffer, 8); - if (retval) + tmp, &buffer, 8); + if (!retval) dev_dbg(&cytherm->udev->dev, "retval = %d\n", retval); - kfree(buffer); - return count; } static DEVICE_ATTR_RW(port1); From patchwork Tue Jan 26 18:33:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12050005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BACEDC433E6 for ; Wed, 27 Jan 2021 12:46:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8AB8B207B1 for ; Wed, 27 Jan 2021 12:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S313688AbhAZWyY (ORCPT ); Tue, 26 Jan 2021 17:54:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394786AbhAZSf4 (ORCPT ); Tue, 26 Jan 2021 13:35:56 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 414FEC0613ED; Tue, 26 Jan 2021 10:35:15 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id r38so6094039pgk.13; Tue, 26 Jan 2021 10:35:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bx/cdqgCma3iJlb8vZQT1JZ3qzb90ip49lgcVaqCQT4=; b=EJMrC+txD3IibE4RjJTLeJTuzedtcFYTmUJkcn1eVGc80DtwSuR/EcGdGNwRSTecPV FtLjuT1AAW/qNN037/aYSj4FeojMzsdii6pt9izxTvfVR5N8KGz/GDFBoV8NMK+9RU+S di1OssSp00gaJ/wyNv9viH8t56ymmxdSX2l6t0o1KlXajkSQiq5bWsnjsOhL73On1ebu oum8vbRWtI7k4qQU1PrJLwtPD2JuiMxx4zBVIw6MDEpaotlhNkoq4SZEd9d8DZfrojUw ibSoB/Ww8ZZcQ2y6cu2vzS6bNfKzgMAPJ0mn91m/YEyNJfMJTlcWH49jqnIt9mDSE4QQ hbxw== 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=bx/cdqgCma3iJlb8vZQT1JZ3qzb90ip49lgcVaqCQT4=; b=PtO6r+xVyMxgKR1Pw1wGGB4JWOFPxN+LZqZHttSd5Y4zrBBRsV+wLApilhHl12nxul Rj6me46g4En97bwf4Alvn6iOojqsG8NsqIgiY/2U9GNld/n80Ddraw/CSny+Uh2j57tu s9vmi9p4yKLx7HFADZADMcSPMSkP3WnopX06L1sg8Dm5y9ueN/8GG6VlRtZTku5fePtp 2Z2d61rW024H9zwFFfIw/vFVTlSNSLcmJArrAZ1jQojLq5NoexojQlADowYiiQdo+10q VZgBWOTCzexNdGi10+aSBS51UKwyXemrxVpSkv7rSkpqfD1VkwijIghupTcxJzEq4KIE cl9A== X-Gm-Message-State: AOAM532u9UlikzGmN3faLkheT2Q87oZa/UniHCT9bzeG9DhIFsGWKYQW UQNuDbUV5Ifohfk39VmhC3/lvHSgrmycR+kyNsE= X-Google-Smtp-Source: ABdhPJxsmzYM41sw3Zm/u83d4UqAR9pPCvyLi9JYwpsBEL3ZWQjorpTAKyBIOVb0F6ZLsN10DPNvqw== X-Received: by 2002:a62:1b95:0:b029:19b:178f:84d7 with SMTP id b143-20020a621b950000b029019b178f84d7mr6633080pfb.70.1611686114735; Tue, 26 Jan 2021 10:35:14 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id y75sm472711pfg.119.2021.01.26.10.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:35:13 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Peter Chen , Minas Harutyunyan , Chunfeng Yun , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 04/12] usb: misc: ehset: update to use the usb_control_msg_{send|recv}() API Date: Wed, 27 Jan 2021 00:03:55 +0530 Message-Id: <20210126183403.911653-5-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, instances of usb_control_msg() have been replaced with usb_control_msg_{recv|send}() appropriately. Signed-off-by: Anant Thazhemadam Reviewed-by: Peter Chen Reviewed-by: Johan Hovold --- drivers/usb/misc/ehset.c | 76 +++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/drivers/usb/misc/ehset.c b/drivers/usb/misc/ehset.c index 2752e1f4f4d0..f87890f9cd26 100644 --- a/drivers/usb/misc/ehset.c +++ b/drivers/usb/misc/ehset.c @@ -24,68 +24,57 @@ static int ehset_probe(struct usb_interface *intf, int ret = -EINVAL; struct usb_device *dev = interface_to_usbdev(intf); struct usb_device *hub_udev = dev->parent; - struct usb_device_descriptor *buf; + struct usb_device_descriptor buf; u8 portnum = dev->portnum; u16 test_pid = le16_to_cpu(dev->descriptor.idProduct); switch (test_pid) { case TEST_SE0_NAK_PID: - ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0), - USB_REQ_SET_FEATURE, USB_RT_PORT, - USB_PORT_FEAT_TEST, - (USB_TEST_SE0_NAK << 8) | portnum, - NULL, 0, 1000); + ret = usb_control_msg_send(hub_udev, 0, USB_REQ_SET_FEATURE, + USB_RT_PORT, USB_PORT_FEAT_TEST, + (USB_TEST_SE0_NAK << 8) | portnum, + NULL, 0, 1000, GFP_KERNEL); break; case TEST_J_PID: - ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0), - USB_REQ_SET_FEATURE, USB_RT_PORT, - USB_PORT_FEAT_TEST, - (USB_TEST_J << 8) | portnum, - NULL, 0, 1000); + ret = usb_control_msg_send(hub_udev, 0, USB_REQ_SET_FEATURE, + USB_RT_PORT, USB_PORT_FEAT_TEST, + (USB_TEST_J << 8) | portnum, NULL, 0, + 1000, GFP_KERNEL); break; case TEST_K_PID: - ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0), - USB_REQ_SET_FEATURE, USB_RT_PORT, - USB_PORT_FEAT_TEST, - (USB_TEST_K << 8) | portnum, - NULL, 0, 1000); + ret = usb_control_msg_send(hub_udev, 0, USB_REQ_SET_FEATURE, + USB_RT_PORT, USB_PORT_FEAT_TEST, + (USB_TEST_K << 8) | portnum, NULL, 0, + 1000, GFP_KERNEL); break; case TEST_PACKET_PID: - ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0), - USB_REQ_SET_FEATURE, USB_RT_PORT, - USB_PORT_FEAT_TEST, - (USB_TEST_PACKET << 8) | portnum, - NULL, 0, 1000); + ret = usb_control_msg_send(hub_udev, 0, USB_REQ_SET_FEATURE, + USB_RT_PORT, USB_PORT_FEAT_TEST, + (USB_TEST_PACKET << 8) | portnum, + NULL, 0, 1000, GFP_KERNEL); break; case TEST_HS_HOST_PORT_SUSPEND_RESUME: /* Test: wait for 15secs -> suspend -> 15secs delay -> resume */ msleep(15 * 1000); - ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0), - USB_REQ_SET_FEATURE, USB_RT_PORT, - USB_PORT_FEAT_SUSPEND, portnum, - NULL, 0, 1000); + ret = usb_control_msg_send(hub_udev, 0, USB_REQ_SET_FEATURE, + USB_RT_PORT, USB_PORT_FEAT_SUSPEND, + portnum, NULL, 0, 1000, GFP_KERNEL); if (ret < 0) break; msleep(15 * 1000); - ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0), - USB_REQ_CLEAR_FEATURE, USB_RT_PORT, - USB_PORT_FEAT_SUSPEND, portnum, - NULL, 0, 1000); + ret = usb_control_msg_send(hub_udev, 0, USB_REQ_CLEAR_FEATURE, + USB_RT_PORT, USB_PORT_FEAT_SUSPEND, + portnum, NULL, 0, 1000, GFP_KERNEL); break; case TEST_SINGLE_STEP_GET_DEV_DESC: /* Test: wait for 15secs -> GetDescriptor request */ msleep(15 * 1000); - buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL); - if (!buf) - return -ENOMEM; - ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, - USB_DT_DEVICE << 8, 0, - buf, USB_DT_DEVICE_SIZE, - USB_CTRL_GET_TIMEOUT); - kfree(buf); + ret = usb_control_msg_recv(dev, 0, USB_REQ_GET_DESCRIPTOR, + USB_DIR_IN, USB_DT_DEVICE << 8, 0, + &buf, USB_DT_DEVICE_SIZE, + USB_CTRL_GET_TIMEOUT, GFP_KERNEL); break; case TEST_SINGLE_STEP_SET_FEATURE: /* @@ -100,11 +89,10 @@ static int ehset_probe(struct usb_interface *intf, break; } - ret = usb_control_msg(hub_udev, usb_sndctrlpipe(hub_udev, 0), - USB_REQ_SET_FEATURE, USB_RT_PORT, - USB_PORT_FEAT_TEST, - (6 << 8) | portnum, - NULL, 0, 60 * 1000); + ret = usb_control_msg_send(hub_udev, 0, USB_REQ_SET_FEATURE, + USB_RT_PORT, USB_PORT_FEAT_TEST, + (6 << 8) | portnum, NULL, 0, + 60 * 1000, GFP_KERNEL); break; default: @@ -112,7 +100,7 @@ static int ehset_probe(struct usb_interface *intf, __func__, test_pid); } - return (ret < 0) ? ret : 0; + return ret; } static void ehset_disconnect(struct usb_interface *intf) From patchwork Tue Jan 26 18:33:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12049999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA8BDC433E0 for ; Wed, 27 Jan 2021 12:46:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EF71207A3 for ; Wed, 27 Jan 2021 12:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S314003AbhAZWya (ORCPT ); Tue, 26 Jan 2021 17:54:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394789AbhAZSgB (ORCPT ); Tue, 26 Jan 2021 13:36:01 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D827DC061786; Tue, 26 Jan 2021 10:35:20 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id u11so10222004plg.13; Tue, 26 Jan 2021 10:35:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rlm5PUymFHRx39FCcGjfRRBHQ3f0wd7qTZT6jsgLwkA=; b=pldzPP87+IAjdQFo5gB4mTAxJDiykolSRf9RJD1R29q+gjloKdScXFVNudyO2fzqLd pKGc4a8CbMMLXXFffBakorBGXvFI86RZ4j54HqOtEntkoiiBUjp223sTRA+iSmxpftjA xLKf34yLq+7cgACxqGLUK7nVpQDDrtZcgzdz8ppQTvf0MLoYNkD0fbs+XTrLz9qVo9Uv 4qRfAPcsocDP0VYL6DYm6hCQRQJpXlLUOJb1Bk9mKW21y4Py/bP4/h9mJPrlQJXqurAH qBOlxTdCrH6skMWJ5s4Ix/QoYqGxilFFEXgDpfGN+vcQUZf8M/B+T0PE8QCqCkIB0p5+ 9i+g== 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=Rlm5PUymFHRx39FCcGjfRRBHQ3f0wd7qTZT6jsgLwkA=; b=d9F0KGX3HtxxiydluBJ9QGcKZa2a3ZOlng1+IFzPP3tAw//6spQAhEknBwgfzApfX/ sD/0KIVldUwq9b7T1opzraPqlhopK+LbNmEWzr6OfT1Vtxfl0Ekh1U4/ETkS+nlEg0JI nX6mhC5gaP0WqyMMaL9MoBF018/+qXoxOauBZu3cWiF2/SrNAsCOSLisx8ZArISXt4Ls zlmvF8tOTZ6yaAs5TXLyrdEEb1J+gAEU24IDdopEjzysP4VCtZqRbmC2MfWM02bmU0Dn 8bg4dJ/kWX6UgKbuHOlclYpSnJdje0QxIYt5OqGgXVBbuzzEZOXRiSmemq5upC/4KquI rlbA== X-Gm-Message-State: AOAM531YqJHyzE8f1SdbuK2LbYQs1pulML/sx9wuo4DvL7KV6waHkn44 56KC+2g0/Gv4qrJTt7xXSrE= X-Google-Smtp-Source: ABdhPJx3PTeB+SUcDOUGdw45AWK8WChpigGSoWVxOGNYaACq2CBMS5O81epaga9lJRTIOjl3cqyexg== X-Received: by 2002:a17:90b:4a4d:: with SMTP id lb13mr1164903pjb.44.1611686120413; Tue, 26 Jan 2021 10:35:20 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id y75sm472711pfg.119.2021.01.26.10.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:35:19 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 05/12] usb: misc: ezusb: update to use usb_control_msg_send() Date: Wed, 27 Jan 2021 00:03:56 +0530 Message-Id: <20210126183403.911653-6-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, the instance of usb_control_msg() has been replaced with usb_control_msg_send() appropriately. Signed-off-by: Anant Thazhemadam Reviewed-by: Johan Hovold --- drivers/usb/misc/ezusb.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/drivers/usb/misc/ezusb.c b/drivers/usb/misc/ezusb.c index f058d8029761..78aaee56c2b7 100644 --- a/drivers/usb/misc/ezusb.c +++ b/drivers/usb/misc/ezusb.c @@ -31,24 +31,12 @@ static const struct ezusb_fx_type ezusb_fx1 = { static int ezusb_writememory(struct usb_device *dev, int address, unsigned char *data, int length, __u8 request) { - int result; - unsigned char *transfer_buffer; - if (!dev) return -ENODEV; - transfer_buffer = kmemdup(data, length, GFP_KERNEL); - if (!transfer_buffer) { - dev_err(&dev->dev, "%s - kmalloc(%d) failed.\n", - __func__, length); - return -ENOMEM; - } - result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request, + return usb_control_msg_send(dev, 0, request, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - address, 0, transfer_buffer, length, 3000); - - kfree(transfer_buffer); - return result; + address, 0, data, length, 3000, GFP_KERNEL); } static int ezusb_set_reset(struct usb_device *dev, unsigned short cpucs_reg, From patchwork Tue Jan 26 18:33:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12050003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 185DCC433E9 for ; Wed, 27 Jan 2021 12:46:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D315F207A9 for ; Wed, 27 Jan 2021 12:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S314010AbhAZWy7 (ORCPT ); Tue, 26 Jan 2021 17:54:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732119AbhAZSh4 (ORCPT ); Tue, 26 Jan 2021 13:37:56 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33B08C061793; Tue, 26 Jan 2021 10:35:33 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id a20so2510295pjs.1; Tue, 26 Jan 2021 10:35:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=95JYXv08LkqT4lJAkAX254N/wQjJtpCwzdAOrY3gErU=; b=Dolr8a9elQ0PIDTVE7L2/3E4EEbsuNSxB0POXTZggKOXxEC16AYD67PxbG/y+9VZt2 NhkfThCDS6LFCKVSaffoL2SUg1DxktM3jYqkgQIESkEoycu26cPJe7aYGzptVzAJ4C4b SZJYU1fPIKOYsg87iWRsRU+aEg60/W+RFyKao9sCZMHwxaS463VVq+Oisuj0BxZFysWw 5YkNxEKdoQx4AcPOmOdsMRvJyRUHSyd+Dy5GUX/qRy6hohOxa96RJrNFyS1MmBblRVLm lLgOY3+bwZvlDgy4BxhXaCJGDKyc/0RI2CvMphFbun+c1G1Z38MJqTfImFduJARcFB5b LnSA== 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=95JYXv08LkqT4lJAkAX254N/wQjJtpCwzdAOrY3gErU=; b=svl8wxFhiJmw7kfIy88tx6EZf5ioW6ixuY0lKtXUB0cupriuxYh7qbCLo1oyZAD5d9 OaXhhgOCh6vvO9tzaFgPfrH0/Al1/XF4XmCY6TW0VriXT5Cd/2hnKPUpMv3XXWLtYQlc /6+RFvnHkZumOLZeVmaetahglNyWiIcoWVYOPz1jtcw182sRjtTwgfBQQ9rADOG6MGyJ cuT+2bNuqlvM9PhOoXt+cPWN7JxbSiW+nTQSm3mgWeYBlAgw69hCVdXg1PKU8h6Veixa 7fZl9PEum0OPNcs1mLbTw3S0C1buyWpVLRz5expm6P1ii5QgFkoZDGSswjKtqZZ6FfU9 EQyA== X-Gm-Message-State: AOAM533tAlPUgzcpko3N+LCixoiN7fpb84haGqwIuqivPEtQBkQkDtaZ G5/p0KoUnRugFb+2wMqd1JA= X-Google-Smtp-Source: ABdhPJxBMu87daLeeLaodAkuXJ/Peu/ZZtm3MNLhjGUOFLlBWGJ5LAus9xQej+0yDB4i0H+E2Ds7/g== X-Received: by 2002:a17:90a:9602:: with SMTP id v2mr1190230pjo.28.1611686132693; Tue, 26 Jan 2021 10:35:32 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id y75sm472711pfg.119.2021.01.26.10.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:35:31 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Lee Jones , Tom Rix , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 06/12] usb: misc: iowarrior: update to use the usb_control_msg_{send|recv}() API Date: Wed, 27 Jan 2021 00:03:57 +0530 Message-Id: <20210126183403.911653-7-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, instances of usb_control_msg() have been replaced with usb_control_msg_{recv|send}() appropriately. Signed-off-by: Anant Thazhemadam --- drivers/usb/misc/iowarrior.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index efbd317f2f25..9d6a7548e537 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c @@ -109,12 +109,12 @@ static int usb_get_report(struct usb_device *dev, struct usb_host_interface *inter, unsigned char type, unsigned char id, void *buf, int size) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_REPORT, - USB_DIR_IN | USB_TYPE_CLASS | - USB_RECIP_INTERFACE, (type << 8) + id, - inter->desc.bInterfaceNumber, buf, size, - GET_TIMEOUT*HZ); + return usb_control_msg_recv(dev, 0, + USB_REQ_GET_REPORT, + USB_DIR_IN | USB_TYPE_CLASS | + USB_RECIP_INTERFACE, (type << 8) + id, + inter->desc.bInterfaceNumber, buf, size, + GET_TIMEOUT*HZ, GFP_KERNEL); } //#endif @@ -123,13 +123,13 @@ static int usb_get_report(struct usb_device *dev, static int usb_set_report(struct usb_interface *intf, unsigned char type, unsigned char id, void *buf, int size) { - return usb_control_msg(interface_to_usbdev(intf), - usb_sndctrlpipe(interface_to_usbdev(intf), 0), - USB_REQ_SET_REPORT, - USB_TYPE_CLASS | USB_RECIP_INTERFACE, - (type << 8) + id, - intf->cur_altsetting->desc.bInterfaceNumber, buf, - size, HZ); + return usb_control_msg_send(interface_to_usbdev(intf), + 0, + USB_REQ_SET_REPORT, + USB_TYPE_CLASS | USB_RECIP_INTERFACE, + (type << 8) + id, + intf->cur_altsetting->desc.bInterfaceNumber, buf, + size, HZ, GFP_KERNEL); } /*---------------------*/ @@ -851,10 +851,10 @@ static int iowarrior_probe(struct usb_interface *interface, /* Set the idle timeout to 0, if this is interface 0 */ if (dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) { - usb_control_msg(udev, usb_sndctrlpipe(udev, 0), - 0x0A, - USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, - 0, NULL, 0, USB_CTRL_SET_TIMEOUT); + usb_control_msg_send(udev, 0, + 0x0A, + USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, + 0, NULL, 0, USB_CTRL_SET_TIMEOUT, GFP_KERNEL); } /* allow device read and ioctl */ dev->present = 1; From patchwork Tue Jan 26 18:33:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12050001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 127A4C433DB for ; Wed, 27 Jan 2021 12:46:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1E9D207B3 for ; Wed, 27 Jan 2021 12:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S313289AbhAZWyw (ORCPT ); Tue, 26 Jan 2021 17:54:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387995AbhAZSh4 (ORCPT ); Tue, 26 Jan 2021 13:37:56 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B2E8C061794; Tue, 26 Jan 2021 10:35:36 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id t29so10925449pfg.11; Tue, 26 Jan 2021 10:35:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=04c9BxYa1Ymi07bLwZCgG59VbrDPFBxGmQMOZz4mzls=; b=FvOQgNCqddAYm4AUTCia19wuZvPbuQkbX+N8R33QYgKyNuRjVwzcgRFgwB6glK1RLE p4jJIbcuu7KymzF9CEGJVoWMCBBc3eDqX0QAoOt+5zhUf8Rrw4o3tvyh71GwD9uM5Rkz LBAuhRPF29reaIxf14OycL3nsyQqVQsJlFIgmARemkK1gyXAiL8Xw8aZSf5s0lZQoFBZ S/KbP5WhAuLS+HrPCMzTLZr3F2XTJLGDdyqLEKABwLyH6y91h4eAXHqtQsfimnStABv9 llQsmlh08D0LJcBeQiHFbunf2IvWPATo4xo4GPqkQJxNPyTV/R8yQUAEePtTw/bUookE NPrg== 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=04c9BxYa1Ymi07bLwZCgG59VbrDPFBxGmQMOZz4mzls=; b=eywgZMqWDOMI3CQqTkgbe1WV/+mIfJbjaTxHHjWMriVrKHqfZA9E8OmmiNgKMDuNpl Un7UUnLPy1N4hJX7GCqOai2RyFWXGZBLaNH7x2/MlN8HcYlJI7Hm9LeA2QsRjLncOLR2 qPl4xv77ofgt1hHDN9Hh+53klR/h4p3cBWTyywVK5ZMxKysxydtKB/5BJhoh7ohydRY6 ZB7A+aY1mZyYPL0hSeJR9faCaqTmEp27np4vnfqpZGaaauPN6FCHgYj253k3ypHm5Yrw oz/qUb2gZCAvrSQyF/ziZxRJldFUc6myTfnnlqd2jNO+8pEbOyzHj1HVuHtwWSA2LO+b Gq4A== X-Gm-Message-State: AOAM530gzj3AfQ0h2NRaGt58rQNOwA8vcuc/i/nGLtoyfSl/PoIaM95f SLprCQAQJEosV7jOhhRybng= X-Google-Smtp-Source: ABdhPJwqDl+lPSKoUI67DOGZaaoeyidOGlselnVweQd3TklIxxtu004ow4RPRps5q4r94389+bcgqw== X-Received: by 2002:a63:560b:: with SMTP id k11mr6954956pgb.89.1611686135847; Tue, 26 Jan 2021 10:35:35 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id y75sm472711pfg.119.2021.01.26.10.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:35:35 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 07/12] usb: misc: isight_firmware: update to use usb_control_msg_send() Date: Wed, 27 Jan 2021 00:03:58 +0530 Message-Id: <20210126183403.911653-8-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, the instances of usb_control_msg() have been replaced with usb_control_msg_send(), and return value checking has also been appropriately enforced. Signed-off-by: Anant Thazhemadam --- drivers/usb/misc/isight_firmware.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/usb/misc/isight_firmware.c b/drivers/usb/misc/isight_firmware.c index 4d30095d6ad2..1bd14a431f6c 100644 --- a/drivers/usb/misc/isight_firmware.c +++ b/drivers/usb/misc/isight_firmware.c @@ -37,13 +37,10 @@ static int isight_firmware_load(struct usb_interface *intf, struct usb_device *dev = interface_to_usbdev(intf); int llen, len, req, ret = 0; const struct firmware *firmware; - unsigned char *buf = kmalloc(50, GFP_KERNEL); + unsigned char buf[50]; unsigned char data[4]; const u8 *ptr; - if (!buf) - return -ENOMEM; - if (request_firmware(&firmware, "isight.fw", &dev->dev) != 0) { printk(KERN_ERR "Unable to load isight firmware\n"); ret = -ENODEV; @@ -53,11 +50,11 @@ static int isight_firmware_load(struct usb_interface *intf, ptr = firmware->data; buf[0] = 0x01; - if (usb_control_msg - (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, 0xe600, 0, buf, 1, - 300) != 1) { + ret = usb_control_msg_send(dev, 0, 0xa0, 0x40, 0xe600, + 0, &buf, 1, 300, GFP_KERNEL); + if (ret != 0) { printk(KERN_ERR - "Failed to initialise isight firmware loader\n"); + "Failed to initialise isight firmware loader\n"); ret = -ENODEV; goto out; } @@ -82,15 +79,15 @@ static int isight_firmware_load(struct usb_interface *intf, ret = -ENODEV; goto out; } - memcpy(buf, ptr, llen); + memcpy(&buf, ptr, llen); ptr += llen; - if (usb_control_msg - (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, req, 0, - buf, llen, 300) != llen) { + ret = usb_control_msg_send(dev, 0, 0xa0, 0x40, req, 0, + &buf, llen, 300, GFP_KERNEL); + if (ret != 0) { printk(KERN_ERR - "Failed to load isight firmware\n"); + "Failed to load isight firmware\n"); ret = -ENODEV; goto out; } @@ -99,15 +96,14 @@ static int isight_firmware_load(struct usb_interface *intf, } buf[0] = 0x00; - if (usb_control_msg - (dev, usb_sndctrlpipe(dev, 0), 0xa0, 0x40, 0xe600, 0, buf, 1, - 300) != 1) { + ret = usb_control_msg_send(dev, 0, 0xa0, 0x40, 0xe600, + 0, &buf, 1, 300, GFP_KERNEL); + if (ret != 0) { printk(KERN_ERR "isight firmware loading completion failed\n"); ret = -ENODEV; } out: - kfree(buf); release_firmware(firmware); return ret; } From patchwork Tue Jan 26 18:33:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12049997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A47DAC433E6 for ; Wed, 27 Jan 2021 12:45:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72E05207B5 for ; Wed, 27 Jan 2021 12:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S314011AbhAZWzH (ORCPT ); Tue, 26 Jan 2021 17:55:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388986AbhAZSiW (ORCPT ); Tue, 26 Jan 2021 13:38:22 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DDF7C061797; Tue, 26 Jan 2021 10:35:41 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id my11so1676515pjb.1; Tue, 26 Jan 2021 10:35:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ulF9m3lqljtgmnGhz+SzghBzSRKlHANlsmi6yEyMAeU=; b=mdkARqUaBx6BYjBGoLgLYxqnNyDZzozEta95Nt4Wx+CmpeY4Su3Ep4Km/eXaTqawLd FhfPBg0TUjr/icrS2cKTIKKjeMsuKstqollbCzy9YqsyxFLt0FkGWttEVeQ/dFu00dbX sKifMG8oLeya/Gw2htNKn1tVBNQzSteP4nDca/kbfYpE6/9qvTxlvOYR9+bj/2xkLuYA cdxG4Jv9HJvHkWbRXEZImf220S1xG0i7aFN+62T3SGt8PQWgwn6CCzu/ONpkOS/UTQ93 +pmHze667S3uRvaRTm59DqbiRg/XV7LZ6h8K4SlrW7ANISM0iMmjPcXL12/EP4iolqIf joag== 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=ulF9m3lqljtgmnGhz+SzghBzSRKlHANlsmi6yEyMAeU=; b=jw3PMn1gOQvH5fc0n96k29VGcW9Dae5rd6OU+Tv0i7kxTf7figXOAIG5zHefVu9XDN OKPcDisKiWly1usjX06mt0Jf8trky8zCKMY/mxoljzb7aM3NM8OYE9q9JjThBvTc9+uz aNne9xIOmRfgvdQNCQToZJepXiMdLNwcjx/pGkPRu24uGY/olK9VT7A+L2I8cCGhYsl2 99GXfZAVpxPbzcfNVQtlTe/wkYPbKwXJ7hk86uYtVURDJuGPiRF3e1VGqKZazTtB3Y/u uGbJDywNgQllDG965bzYUXI2YQjaXx6Gy++6DXzNXNef6USUZUkzKIcJ38CzReoAcqRN IIvw== X-Gm-Message-State: AOAM530AOYdd0D/gJbrz4CSWQWwOW/nV3ARTjI8Z5WI8vVRuqTu3piyw dWxYXPmfzWP5wMOZcrIIonY= X-Google-Smtp-Source: ABdhPJy6lhnce8iilLJcfvNf5E8E51/GvUznO8hznRRkxLqV7nDlbWGG5fGC75DRp6djnGnL1uVNUQ== X-Received: by 2002:a17:90b:8d1:: with SMTP id ds17mr1149476pjb.194.1611686140789; Tue, 26 Jan 2021 10:35:40 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id y75sm472711pfg.119.2021.01.26.10.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:35:40 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Lee Jones , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 08/12] usb: misc: ldusb: update to use usb_control_msg_send() Date: Wed, 27 Jan 2021 00:03:59 +0530 Message-Id: <20210126183403.911653-9-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, the instance of usb_control_msg_send() has been replaced with usb_control_msg_send() appropriately. Signed-off-by: Anant Thazhemadam --- drivers/usb/misc/ldusb.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c index 670e4d91e9ca..259ead4edecb 100644 --- a/drivers/usb/misc/ldusb.c +++ b/drivers/usb/misc/ldusb.c @@ -573,15 +573,13 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer, } if (dev->interrupt_out_endpoint == NULL) { - /* try HID_REQ_SET_REPORT=9 on control_endpoint instead of interrupt_out_endpoint */ - retval = usb_control_msg(interface_to_usbdev(dev->intf), - usb_sndctrlpipe(interface_to_usbdev(dev->intf), 0), - 9, + retval = usb_control_msg_send(interface_to_usbdev(dev->intf), + 0, 9, USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, 1 << 8, 0, dev->interrupt_out_buffer, bytes_to_write, - USB_CTRL_SET_TIMEOUT); + USB_CTRL_SET_TIMEOUT, GFP_KERNEL); if (retval < 0) dev_err(&dev->intf->dev, "Couldn't submit HID_REQ_SET_REPORT %d\n", From patchwork Tue Jan 26 18:39:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12049941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80049C433E6 for ; Wed, 27 Jan 2021 12:29:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35A1420793 for ; Wed, 27 Jan 2021 12:29:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S314018AbhAZWzK (ORCPT ); Tue, 26 Jan 2021 17:55:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393820AbhAZSkl (ORCPT ); Tue, 26 Jan 2021 13:40:41 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87596C061756; Tue, 26 Jan 2021 10:40:01 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id w14so10946822pfi.2; Tue, 26 Jan 2021 10:40:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oc1Y4NMhbCVXiBqEN7io2NrC3w9YKQLRDFoQx1B3ae0=; b=BRcBOxwnrhqqL5HPkPKHY2RfFpihmcP3eXkWI3lfIyzbHZMYS/oWxpVQpipvsCbtMS 06w/N3oueLFZvM+QAR8xalsQk2caRbcQZKP7KNzHsU1R8sdN7scbWiKdt+4TYxxVxbBH G574fkdZYOUkqbk/uGcd3WV5dS3ujEwFXyd1puKoy/682V7CFPkygZKwtsii/2dF5poX pXFxXOHrNyPmUzh6OkZtuQdFlHlBa2UOvtq5QY1jnXnntdGfD5A8rEOSZk2eTtXy0RLM ZuV/Kk+9xJIvzhq5FpR4e/rQ8AplJARbRhxxXJtNCZjeluN45H6ivEFqNI+Fsg/koDAw FsRw== 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=oc1Y4NMhbCVXiBqEN7io2NrC3w9YKQLRDFoQx1B3ae0=; b=hqSLXSDgtxE0BMOYsoEmfldaiqWS8PplXb/Lfx45DOzSmxadt3OL18sp8hUhZFf74t e2B7Fo/2B5N8V8NK3vClPyqThyF3bhEWpxZycVR8oESGmY/ikVFRCgwRRzdD6KCcTzAc YuCmM3YqS3bhEsvngig7Q3P1FNWjk9RJSn1w0553owS/L+AebePC8wf0fRHlm7OoAekg TjK7lfSJee5bRGF2TYRP1K7+3Badi3r4ZLaO8RgV4voFTcEJ8NogFvKNKy7javH4ma1I LPPEHA+pUAPt7W+XhW1bNaT2sRdlc3yJs942nrjs1skpuSqKnILWHsR+bjf+PC8to9wp jB+g== X-Gm-Message-State: AOAM531lYO01ENI4vQr+fuLo1mdZowV43CyMrfiy053QVD9rAykPTgCt vf74KDwTgB8EC57AmFnalZw= X-Google-Smtp-Source: ABdhPJzYLh5KPPyyEPbfFExkULcireYYex7FMizRdkQN0zYFlxx/ENcNe/Br7APfIQY3RX3htU/stQ== X-Received: by 2002:a63:5004:: with SMTP id e4mr7011098pgb.338.1611686401050; Tue, 26 Jan 2021 10:40:01 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id ge16sm2945273pjb.41.2021.01.26.10.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:40:00 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Anant Thazhemadam , Evgeny Novikov Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 09/12] usb: misc: lvstest: update to use the usb_control_msg_{send|recv}() API Date: Wed, 27 Jan 2021 00:09:43 +0530 Message-Id: <20210126183943.914631-1-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, instances of usb_control_msg() have been replaced with usb_control_msg_{recv|send}() and the return value checking conditions have also been modified appropriately. Signed-off-by: Anant Thazhemadam --- drivers/usb/misc/lvstest.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/drivers/usb/misc/lvstest.c b/drivers/usb/misc/lvstest.c index f8686139d6f3..daa1b2c9139f 100644 --- a/drivers/usb/misc/lvstest.c +++ b/drivers/usb/misc/lvstest.c @@ -85,17 +85,17 @@ static void destroy_lvs_device(struct usb_device *udev) static int lvs_rh_clear_port_feature(struct usb_device *hdev, int port1, int feature) { - return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + return usb_control_msg_send(hdev, 0, USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port1, - NULL, 0, 1000); + NULL, 0, 1000, GFP_KERNEL); } static int lvs_rh_set_port_feature(struct usb_device *hdev, int port1, int feature) { - return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), + return usb_control_msg_send(hdev, 0, USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port1, - NULL, 0, 1000); + NULL, 0, 1000, GFP_KERNEL); } static ssize_t u3_entry_store(struct device *dev, @@ -257,13 +257,9 @@ static ssize_t get_dev_desc_store(struct device *dev, { struct usb_interface *intf = to_usb_interface(dev); struct usb_device *udev; - struct usb_device_descriptor *descriptor; + struct usb_device_descriptor descriptor; int ret; - descriptor = kmalloc(sizeof(*descriptor), GFP_KERNEL); - if (!descriptor) - return -ENOMEM; - udev = create_lvs_device(intf); if (!udev) { dev_err(dev, "failed to create lvs device\n"); @@ -271,18 +267,16 @@ static ssize_t get_dev_desc_store(struct device *dev, goto free_desc; } - ret = usb_control_msg(udev, (PIPE_CONTROL << 30) | USB_DIR_IN, - USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, USB_DT_DEVICE << 8, - 0, descriptor, sizeof(*descriptor), - USB_CTRL_GET_TIMEOUT); + ret = usb_control_msg_recv(udev, 0, USB_REQ_GET_DESCRIPTOR, + USB_DIR_IN, USB_DT_DEVICE << 8, + 0, &descriptor, sizeof(descriptor), + USB_CTRL_GET_TIMEOUT, GFP_KERNEL); if (ret < 0) dev_err(dev, "can't read device descriptor %d\n", ret); destroy_lvs_device(udev); free_desc: - kfree(descriptor); - if (ret < 0) return ret; @@ -336,10 +330,10 @@ static void lvs_rh_work(struct work_struct *work) /* Examine each root port */ for (i = 1; i <= descriptor->bNbrPorts; i++) { - ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), + ret = usb_control_msg_recv(hdev, 0, USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, i, - port_status, sizeof(*port_status), 1000); - if (ret < 4) + port_status, sizeof(*port_status), 1000, GFP_KERNEL); + if (ret < 0) continue; portchange = le16_to_cpu(port_status->wPortChange); @@ -420,13 +414,13 @@ static int lvs_rh_probe(struct usb_interface *intf, usb_set_intfdata(intf, lvs); /* how many number of ports this root hub has */ - ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), + ret = usb_control_msg_recv(hdev, 0, USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, USB_DT_SS_HUB << 8, 0, &lvs->descriptor, - USB_DT_SS_HUB_SIZE, USB_CTRL_GET_TIMEOUT); - if (ret < (USB_DT_HUB_NONVAR_SIZE + 2)) { + USB_DT_SS_HUB_SIZE, USB_CTRL_GET_TIMEOUT, GFP_KERNEL); + if (ret < 0) { dev_err(&hdev->dev, "wrong root hub descriptor read %d\n", ret); - return ret < 0 ? ret : -EINVAL; + return ret; } /* submit urb to poll interrupt endpoint */ From patchwork Tue Jan 26 18:40:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12049939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37C71C433DB for ; Wed, 27 Jan 2021 12:27:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF8BA2070E for ; Wed, 27 Jan 2021 12:27:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S314028AbhAZWzP (ORCPT ); Tue, 26 Jan 2021 17:55:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389138AbhAZSlA (ORCPT ); Tue, 26 Jan 2021 13:41:00 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54B2DC0613D6; Tue, 26 Jan 2021 10:40:20 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id s15so10240431plr.9; Tue, 26 Jan 2021 10:40:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oMoEajyDR9iy/8AmtoE+xZAQV9/TdmV8a3AZX9/gsow=; b=EF26dfb3eED5YtxaqteBfV8MDvCUudo3W9MhQH2ZK388/AzZVFdpsg8UO2AFxPTv7Z GiZ99Fqrm5Igv+DWOpyDZ+Bs9WL9asQDedlewINodicAp/+Ch5Xjkav/6YKEKaC5F173 Tsw/HlEIFaCRywjFnzRNYPvgcZ+jbGREHvF/h9Mc3n+fkf10p3ZEWR/he+uUzaxz5ezd Ep+I7+kb0kRhrx5LatHqduLET0e3RQlMQIddpg+sN2y6b+GMCXHj5DSjZQU3CLDmIirc b5RqjJGcKLGw81K1hPXO3bMorPfm9OT5Bo5+UjqQclFOMs0vAPyELbZOWYpGjpuh5ILF eaBQ== 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=oMoEajyDR9iy/8AmtoE+xZAQV9/TdmV8a3AZX9/gsow=; b=HgQ118wBlfoQsQkQ2JSa5CQUqclGScNEIgr1OsCjcjP7d+XJmWfbSaDkoR6BaXTm8z zzwNToW5QLGORVXgouQdafU8VvYBApl4ZXHIlpNYVO3pDt08h8riuc5+5hbgKpiJff7G AqtYxUHNY1kDslkAuuTEf1lLpCo5K2O7kC9yO+6r+NDRpLNr6ycQ+wn63nE9qgl+WjNq wMpb7npI9PlBaePrAGJ2mJAgzW0R2T796qunoL7zyFDWGxcLMBYZgyMzZcEYfMQM0DV+ 8ZgfS5sEgdGe0Vk3rsWrV3t2OPBB9Em4B74alf2zZlB0+pGUxXNsIFQGc01ZE4lOJwmJ LknQ== X-Gm-Message-State: AOAM5324E7SexkIw/nRVJA8Vcv57gRZLvZsWpVJpXcUoRMsS35Vep7bN ipBDrTtYDfRlRrJi3RdAQoA= X-Google-Smtp-Source: ABdhPJwl3jRKxfO70x4lMp4CvvCr4Oh4KYm73OCOVv3zzrkC17DlZ8JarQaGzAWHUtCJYPT1cFvfSw== X-Received: by 2002:a17:902:8213:b029:e0:1096:7eec with SMTP id x19-20020a1709028213b02900e010967eecmr4704370pln.50.1611686419832; Tue, 26 Jan 2021 10:40:19 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id h3sm19097435pgm.67.2021.01.26.10.40.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:40:19 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 10/12] usb: misc: trancevibrator: update to use usb_control_msg_send() Date: Wed, 27 Jan 2021 00:10:10 +0530 Message-Id: <20210126184010.914841-1-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, the instance of usb_control_msg() has been replaced with usb_control_msg_send() and the return value checking condition has also been modified appropriately. Signed-off-by: Anant Thazhemadam --- drivers/usb/misc/trancevibrator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/misc/trancevibrator.c b/drivers/usb/misc/trancevibrator.c index a3dfc77578ea..c50807b4f4ef 100644 --- a/drivers/usb/misc/trancevibrator.c +++ b/drivers/usb/misc/trancevibrator.c @@ -59,11 +59,11 @@ static ssize_t speed_store(struct device *dev, struct device_attribute *attr, dev_dbg(&tv->udev->dev, "speed = %d\n", tv->speed); /* Set speed */ - retval = usb_control_msg(tv->udev, usb_sndctrlpipe(tv->udev, 0), + retval = usb_control_msg_send(tv->udev, 0, 0x01, /* vendor request: set speed */ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, tv->speed, /* speed value */ - 0, NULL, 0, USB_CTRL_GET_TIMEOUT); + 0, NULL, 0, USB_CTRL_GET_TIMEOUT, GFP_KERNEL); if (retval) { tv->speed = old; dev_dbg(&tv->udev->dev, "retval = %d\n", retval); From patchwork Tue Jan 26 18:40:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12049937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7592C43381 for ; Wed, 27 Jan 2021 12:27:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 89B6920759 for ; Wed, 27 Jan 2021 12:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S314035AbhAZWzY (ORCPT ); Tue, 26 Jan 2021 17:55:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391515AbhAZSlS (ORCPT ); Tue, 26 Jan 2021 13:41:18 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8B6EC0613ED; Tue, 26 Jan 2021 10:40:37 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id 11so10953621pfu.4; Tue, 26 Jan 2021 10:40:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=idqo+EX1CIZxF2ePxyjSJLOfFZLABQRqNBSPoIAo4yo=; b=JSjq6hw/4Q+OJ/8jKFtDDBalwqLAyr72EP5vqQPoaXDN1Tcd2WYE/XfM/GgHMddqV3 JRfFdcrEfnmpSgxM0dW/mnVsEZKgzfzk+QRtfYSVruEJY+EeabHSpqqT/kJdmWgbSWZw Rt83Wbit9FA5fK1BoFwGadywKsLjnmthQvEsMEg2pDnxAbVT5FnZXKUlHn5JGe+smGU+ gN6hDLHxvw5EXhEJS+JqELHsMtSs3skNrqC16RX+sRYkDHATONFBJ5EVGliZ+b5rbWnc HzUstc4Q1aeLoEFgo4TmuRLiZjyc4lv5x9ISPQBwqT0u8hh0YpgXiNIB8IgXTAP29lti GI7Q== 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=idqo+EX1CIZxF2ePxyjSJLOfFZLABQRqNBSPoIAo4yo=; b=mpL4eOjT7p3PYb+z+g/6SRAeYXV40f1j+QPJqXKeiU9De9NlJBdEfQbLH+bR5GebiF 4wA4aScOMapIqZI2XItzG7RU6ffEZmeLil4g4EE8LvtrIUxTCEgGpjOajRFY4b5qNTI5 H/ECNKqKy54TmkdQGtpI2sFyP/5IFWU2BjABDjuFoDP1HxImLc8m31kh2gr3dFDTvg/G bCDJ3JgUXnqGWN+Sa183AtHcjPTV9HbwpvotiZ70t1vsyGsSrovTjauue0rIE2gu0ur2 fDLfJ2qzM1wIqDj8OlNwLy7SLV9DpSDPDgd+Ggq69q3bKnhdtNzGZNEAhL2UuLVVCKti DshQ== X-Gm-Message-State: AOAM533QEGFPIv48ebwLoAhPWx+eR/mH6watQNJ0W4VQ1J1fr9ltTO+0 6yQYP6EgMXVF9mGkThs3E7fXgn5ua8jOoHyehGY= X-Google-Smtp-Source: ABdhPJxDolp46jsFpRwvuw8qL2oRbxyvF6axLE8GV8jw0vSIKJitluA9VEC1CLfRF7qU3rrcI0/EpA== X-Received: by 2002:a63:ce42:: with SMTP id r2mr7042705pgi.8.1611686437369; Tue, 26 Jan 2021 10:40:37 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id q17sm14003682pfl.143.2021.01.26.10.40.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 10:40:36 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Anant Thazhemadam Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 11/12] usb: misc: usbsevseg: update to use usb_control_msg_send() Date: Wed, 27 Jan 2021 00:10:30 +0530 Message-Id: <20210126184030.915039-1-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, instances of usb_control_msg() have been replaced with usb_control_msg_send() appropriately. Signed-off-by: Anant Thazhemadam --- drivers/usb/misc/usbsevseg.c | 60 ++++++++++-------------------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/drivers/usb/misc/usbsevseg.c b/drivers/usb/misc/usbsevseg.c index 551074f5b7ad..ade4bc58d5f2 100644 --- a/drivers/usb/misc/usbsevseg.c +++ b/drivers/usb/misc/usbsevseg.c @@ -74,15 +74,10 @@ static void update_display_powered(struct usb_sevsegdev *mydev) if (mydev->shadow_power != 1) return; - rc = usb_control_msg(mydev->udev, - usb_sndctrlpipe(mydev->udev, 0), - 0x12, - 0x48, - (80 * 0x100) + 10, /* (power mode) */ - (0x00 * 0x100) + (mydev->powered ? 1 : 0), - NULL, - 0, - 2000); + rc = usb_control_msg_send(mydev->udev, 0, 0x12, 0x48, + (80 * 0x100) + 10, /* (power mode) */ + (0x00 * 0x100) + (mydev->powered ? 1 : 0), + NULL, 0, 2000, GFP_KERNEL); if (rc < 0) dev_dbg(&mydev->udev->dev, "power retval = %d\n", rc); @@ -99,15 +94,10 @@ static void update_display_mode(struct usb_sevsegdev *mydev) if(mydev->shadow_power != 1) return; - rc = usb_control_msg(mydev->udev, - usb_sndctrlpipe(mydev->udev, 0), - 0x12, - 0x48, - (82 * 0x100) + 10, /* (set mode) */ - (mydev->mode_msb * 0x100) + mydev->mode_lsb, - NULL, - 0, - 2000); + rc = usb_control_msg_send(mydev->udev, 0, 0x12, 0x48, + (82 * 0x100) + 10, /* (set mode) */ + (mydev->mode_msb * 0x100) + mydev->mode_lsb, + NULL, 0, 2000, GFP_KERNEL); if (rc < 0) dev_dbg(&mydev->udev->dev, "mode retval = %d\n", rc); @@ -117,48 +107,32 @@ static void update_display_visual(struct usb_sevsegdev *mydev, gfp_t mf) { int rc; int i; - unsigned char *buffer; + unsigned char buffer[MAXLEN] = {0}; u8 decimals = 0; if(mydev->shadow_power != 1) return; - buffer = kzalloc(MAXLEN, mf); - if (!buffer) - return; - /* The device is right to left, where as you write left to right */ for (i = 0; i < mydev->textlength; i++) buffer[i] = mydev->text[mydev->textlength-1-i]; - rc = usb_control_msg(mydev->udev, - usb_sndctrlpipe(mydev->udev, 0), - 0x12, - 0x48, - (85 * 0x100) + 10, /* (write text) */ - (0 * 0x100) + mydev->textmode, /* mode */ - buffer, - mydev->textlength, - 2000); + rc = usb_control_msg_send(mydev->udev, 0, 0x12, 0x48, + (85 * 0x100) + 10, /* (write text) */ + (0 * 0x100) + mydev->textmode, /* mode */ + &buffer, mydev->textlength, 2000, mf); if (rc < 0) dev_dbg(&mydev->udev->dev, "write retval = %d\n", rc); - kfree(buffer); - /* The device is right to left, where as you write left to right */ for (i = 0; i < sizeof(mydev->decimals); i++) decimals |= mydev->decimals[i] << i; - rc = usb_control_msg(mydev->udev, - usb_sndctrlpipe(mydev->udev, 0), - 0x12, - 0x48, - (86 * 0x100) + 10, /* (set decimal) */ - (0 * 0x100) + decimals, /* decimals */ - NULL, - 0, - 2000); + rc = usb_control_msg_send(mydev->udev, 0, 0x12, 0x48, + (86 * 0x100) + 10, /* (set decimal) */ + (0 * 0x100) + decimals, /* decimals */ + NULL, 0, 2000, mf); if (rc < 0) dev_dbg(&mydev->udev->dev, "decimal retval = %d\n", rc); From patchwork Wed Jan 27 12:12:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anant Thazhemadam X-Patchwork-Id: 12049929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34282C433E9 for ; Wed, 27 Jan 2021 12:22:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E99BA20786 for ; Wed, 27 Jan 2021 12:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237819AbhA0MVz (ORCPT ); Wed, 27 Jan 2021 07:21:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237336AbhA0MOk (ORCPT ); Wed, 27 Jan 2021 07:14:40 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4E32C061573; Wed, 27 Jan 2021 04:13:59 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id md11so1154087pjb.0; Wed, 27 Jan 2021 04:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YLLhgi+NiVGDqhBaYQHDfMrKV4DMWFVLqCYi85ZNzho=; b=K/LKbJ18NNtDlWPKhhN9q8pyPtPZcXJNc0IclJOz2d4MmqjquK68m1DYuIAIObBQjx S8bV5zkpxajM1TXSWIILfAA+BMOBLmnQT7MMuTTU0vIk4tckHYSivJ3jGocs/rWjw5CC L01TVUA+PGr2MMvekkAHBI+HuGlmsBaGXnSKkT3l6AXIkTLw8U+7U9Ijqr3OpqGfneno AVpfI4EwEg1Dzq2l8YrvEmwzJco05mk89YZKwABIpHVexBioetJBQGuqkBJOyzMFkWo9 26a8VcKrkx0aaD2H21dK75yGbfbf+0cYq3oMNWNuBlneq71AeR4pimCYtCJqYDRQWIVb 394w== 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=YLLhgi+NiVGDqhBaYQHDfMrKV4DMWFVLqCYi85ZNzho=; b=Gvl9dC3MsblE4tvKst+tZG+gw/L14t1+caAMgHj2Zqp2zH18cu2yV78ZYaZN01H03s AF1IXN3afurCrMuphoBuF2Pfn9inictVZH8UR3/ZNvhSwjZjS9HZDIv6XdP9rF5AxjbP cMsZ1wpcwOyxkkI/H9TChbMYe2xK4d/denwaU1VZs2GWUjjkbadCI+QAKR6nV7uzw9B/ O8XG8IP0UwGeQ9Yl0q/XuAhd+W/0zLGfcKyw9T9sm+UOuJZz8k3vxXJhAGqkZpjd4Vn/ 1nxuO5QUIgWdUFwNpRcTKQ3OJLzkblRB6MmkWXE+YTlAjfwnP6J+bUrt9RrXPtUbNwhn Guxw== X-Gm-Message-State: AOAM53084di7D2n8x+pMglWcOqIBGohwR1X/scUe6SWQ4XKQN/p64eMs MYOWu6YZZGCYNef51V4XbYo= X-Google-Smtp-Source: ABdhPJwGlxqoH0mpc3HshizQEQaAmfuPRd9Ap8ytEXfRDlWeUY6tHV3ZCb0e9VW5oWGOTadzRqU9sA== X-Received: by 2002:a17:903:1c2:b029:de:ad0a:2dbf with SMTP id e2-20020a17090301c2b02900dead0a2dbfmr11190998plh.44.1611749639192; Wed, 27 Jan 2021 04:13:59 -0800 (PST) Received: from localhost.localdomain ([49.207.195.86]) by smtp.gmail.com with ESMTPSA id 67sm2365488pfv.20.2021.01.27.04.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 04:13:58 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Alan Stern , Anant Thazhemadam , Bixuan Cui , "Gustavo A. R. Silva" , Zqiang Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH v3 12/12] usb: misc: usbtest: update to use the usb_control_msg_{send|recv}() API Date: Wed, 27 Jan 2021 17:42:47 +0530 Message-Id: <20210127121247.9938-1-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126183403.911653-1-anant.thazhemadam@gmail.com> References: <20210126183403.911653-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newer usb_control_msg_{send|recv}() API are an improvement on the existing usb_control_msg() as it ensures that a short read/write is treated as an error, data can be used off the stack, and raw usb pipes need not be created in the calling functions. For this reason, instances of usb_control_msg() have been replaced with usb_control_msg_{recv|send}() and the return value checking conditions have also been modified appropriately. Signed-off-by: Anant Thazhemadam --- Resending this patch since the subject line for the initial submission (sent as a part of the patch series) wasn't set correctly. drivers/usb/misc/usbtest.c | 69 ++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index 150090ee4ec1..4337eff2a749 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c @@ -672,19 +672,15 @@ static int get_altsetting(struct usbtest_dev *dev) struct usb_device *udev = interface_to_usbdev(iface); int retval; - retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), - USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE, - 0, iface->altsetting[0].desc.bInterfaceNumber, - dev->buf, 1, USB_CTRL_GET_TIMEOUT); - switch (retval) { - case 1: - return dev->buf[0]; - case 0: - retval = -ERANGE; - fallthrough; - default: + retval = usb_control_msg_recv(udev, 0, USB_REQ_GET_INTERFACE, + USB_DIR_IN|USB_RECIP_INTERFACE, + 0, iface->altsetting[0].desc.bInterfaceNumber, + dev->buf, 1, USB_CTRL_GET_TIMEOUT, GFP_KERNEL); + + if (retval < 0) return retval; - } + + return dev->buf[0]; } static int set_altsetting(struct usbtest_dev *dev, int alternate) @@ -872,14 +868,15 @@ static int ch9_postconfig(struct usbtest_dev *dev) * ... although some cheap devices (like one TI Hub I've got) * won't return config descriptors except before set_config. */ - retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), - USB_REQ_GET_CONFIGURATION, - USB_DIR_IN | USB_RECIP_DEVICE, - 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); - if (retval != 1 || dev->buf[0] != expected) { + retval = usb_control_msg_recv(udev, 0, USB_REQ_GET_CONFIGURATION, + USB_DIR_IN | USB_RECIP_DEVICE, 0, + 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT, + GFP_KERNEL); + + if (retval != 0 || dev->buf[0] != expected) { dev_err(&iface->dev, "get config --> %d %d (1 %d)\n", retval, dev->buf[0], expected); - return (retval < 0) ? retval : -EDOM; + return retval; } } @@ -1683,10 +1680,10 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb) return retval; /* set halt (protocol test only), verify it worked */ - retval = usb_control_msg(urb->dev, usb_sndctrlpipe(urb->dev, 0), - USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT, - USB_ENDPOINT_HALT, ep, - NULL, 0, USB_CTRL_SET_TIMEOUT); + retval = usb_control_msg_send(urb->dev, 0, USB_REQ_SET_FEATURE, + USB_RECIP_ENDPOINT, USB_ENDPOINT_HALT, + ep, NULL, 0, USB_CTRL_SET_TIMEOUT, + GFP_KERNEL); if (retval < 0) { ERROR(tdev, "ep %02x couldn't set halt, %d\n", ep, retval); return retval; @@ -1845,30 +1842,22 @@ static int ctrl_out(struct usbtest_dev *dev, /* write patterned data */ for (j = 0; j < len; j++) buf[j] = (u8)(i + j); - retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), - 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR, - 0, 0, buf, len, USB_CTRL_SET_TIMEOUT); - if (retval != len) { + retval = usb_control_msg_send(udev, 0, 0x5b, + USB_DIR_OUT | USB_TYPE_VENDOR, 0, + 0, buf, len, USB_CTRL_SET_TIMEOUT, + GFP_KERNEL); + if (retval < 0) { what = "write"; - if (retval >= 0) { - ERROR(dev, "ctrl_out, wlen %d (expected %d)\n", - retval, len); - retval = -EBADMSG; - } break; } /* read it back -- assuming nothing intervened!! */ - retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), - 0x5c, USB_DIR_IN|USB_TYPE_VENDOR, - 0, 0, buf, len, USB_CTRL_GET_TIMEOUT); - if (retval != len) { + retval = usb_control_msg_recv(udev, 0, + 0x5c, USB_DIR_IN|USB_TYPE_VENDOR, + 0, 0, buf, len, USB_CTRL_GET_TIMEOUT, + GFP_KERNEL); + if (retval < 0) { what = "read"; - if (retval >= 0) { - ERROR(dev, "ctrl_out, rlen %d (expected %d)\n", - retval, len); - retval = -EBADMSG; - } break; }