Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3168720pxu; Sun, 29 Nov 2020 17:37:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMDd1xwMh8dlGNMhM9YFcRqx/GPY/1cLTSHOsgyfEs7eicySC13bXCXk6XSCZl8Rq/Gceb X-Received: by 2002:a50:fd8d:: with SMTP id o13mr19736984edt.248.1606700249416; Sun, 29 Nov 2020 17:37:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606700249; cv=none; d=google.com; s=arc-20160816; b=papQEOqCqMW+WqnSOA20gcR2B9orYlH0I9QiS/Wq18M7TMOVXvXd8KKPjCwn36SqOu Xqc7eWawDGxXGkdUSag7+j+jUOJqOoVAivhN6Zi6B3StQGmWOlnrHmoSOT1KCT76C2sG GuqrZ48xZ/cKTQqhM8bbLLcvJ8I/vQptdieQHx881ePVBwZhuRvutt44UpvKKTqQoKsH ZK9hOp+Hhc5QS92UR1LgrYfhnytfy76922yUxlaC3p5wxKj1DxGbGl/rp0XRo0NmS6Wr qAKf6E3z+wkL5YuFlcZDGN+wgZgFMiO+jipUZkaOc70LJsHeexD9KkA02OLA1tjsEPoZ qung== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MRf4ZKc/l/eC7hFvdoC+Q4DO+7qNVyq14MdwpxFRyF4=; b=XWrLzvXWOxvMEYnBzfIGxO/xSnVPd2yyNqyo5+BymwpgIa0fIr6FfLzJcGMISpYI6H 42AchMXBi4RosNnwXtK75EMYJEVAaX2pgFn6bOiyR97yME0TbdMOId8KZvJ+cQB+T9r+ Z28el7mFr/25OagxNTAxGxXdxqYVOhmmHyJubcKoxrMv6kNEREUiG9KrcOTppeKZilxB keHyQiZBh+eKEYeCEv8BE4ujraVlABPHOt7LHiw4kKsc2JxZsLjF7E2MUb0Sp71VKc0B kDfy8dZnHwbiTFkxnrAeZt+8m+p+Z9g59taN+h2a5mp5q3vnDwyJ1GFsrzTmuSPLC83G 954w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G1ZxR9Tk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si8405915ejy.251.2020.11.29.17.37.06; Sun, 29 Nov 2020 17:37:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G1ZxR9Tk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728794AbgK3BfN (ORCPT + 99 others); Sun, 29 Nov 2020 20:35:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727028AbgK3BfM (ORCPT ); Sun, 29 Nov 2020 20:35:12 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9ABBC0613D2; Sun, 29 Nov 2020 17:34:32 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id n137so9398883pfd.3; Sun, 29 Nov 2020 17:34:32 -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=MRf4ZKc/l/eC7hFvdoC+Q4DO+7qNVyq14MdwpxFRyF4=; b=G1ZxR9TkgoW8diPH06BgSmIXKYidGd9LgBebSIwX0TWLjOX0xJmKKv67iCR5getn7r F7TKZVzfPzxw08bbKFbMm9Imcx1CvSk5EsFakblE6/MTcZBjM1tq0x3mImWeb5JhPsLr ezr0XTJ7gKr5J/xbzjsNRDXFWKmYABaKmtJissHCKRnvydqPvDwTT5gDWkCuy7O6dkxx 1f1BM1i5tu3rK5UCdxKOQLaJg2rBSYRzs2Fr004b0BrABdWZVXSuVc6cAHJlqbMYdczv g3xQwwvfROsl2MjrJZ7WoduuL0d0a/OswWVLv34SbCYzp5WQUk5AzznGv3cvz9AUoW1s UXbg== 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=MRf4ZKc/l/eC7hFvdoC+Q4DO+7qNVyq14MdwpxFRyF4=; b=CIe3ehLSetllqNOIznPj+d0+sDjMFNYM52by6Hp3WylMlmNj5w4it25oVBiNV0Sesu TIA2KyYxMOF3nUtqbFZJLnfkuGq7jKYLOD3ypkfrNaecV6OaaMk0SwShAW0ekG5rny/6 E2my0K7JCu+OjGP9R8/BqhciihYR2CrqWPXo7swIYnuRvXNZzJdsYv8RfGcqxByfAqjA 4qvPzmxd3sCKdxycIavqWeECIIfcceSUXdafpzTdvegrhiR12yFhdtT1plllllJCcSJM xw9Iy2n4THO3O2Fpnpac1XZqyT9s8q1VrCb6R2woQvlgKOAsoilt2JUSeYDeU7hnjyiG Joww== X-Gm-Message-State: AOAM530240RVveszRGqExeOAKGJxvKlWyw9pgiGlmYlfRROpnQ7J4sE+ BW5bB242F+KFOOOFeZ1lnSs= X-Received: by 2002:a63:e54b:: with SMTP id z11mr3477173pgj.158.1606700072181; Sun, 29 Nov 2020 17:34:32 -0800 (PST) Received: from localhost.localdomain ([49.207.197.72]) by smtp.gmail.com with ESMTPSA id k1sm13933508pgm.21.2020.11.29.17.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2020 17:34:31 -0800 (PST) From: Anant Thazhemadam To: Greg Kroah-Hartman , Alan Stern , Bixuan Cui , Anant Thazhemadam , Zqiang , "Gustavo A. R. Silva" Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 15/15] usb: misc: usbtest: update to use the usb_control_msg_{send|recv}() API Date: Mon, 30 Nov 2020 07:04:23 +0530 Message-Id: <20201130013423.2582099-1-anant.thazhemadam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201130011819.2576481-1-anant.thazhemadam@gmail.com> References: <20201130011819.2576481-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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/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; } -- 2.25.1