Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp453761pxb; Wed, 27 Jan 2021 11:49:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhdin4brkcrRGVb3e/grL5UY4bWhdz8ILkACKs3CasIg2qsgvaZua9J6ktPKR2E+tfwzd2 X-Received: by 2002:a17:906:a0c:: with SMTP id w12mr7847256ejf.211.1611776994995; Wed, 27 Jan 2021 11:49:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611776994; cv=none; d=google.com; s=arc-20160816; b=wgjMmjGE+/hkRdr+8BPUJqcfGyhSktyTxP0kMDfQTWYGkvrxqc50kFxsh21a+AOYEH gLEF1JfCo3ZsljJQqzzMSrCy3hp9zRFXmTvxWULqFj9ZIjh+G+WV08+R7mIlc4ViVleo G4D9o60wpNTsvQ4SYn0Tj7XkEwSLzocJbc4oiMMzSrcpso/s3AbPhU+y8hXr2SgDAAmQ jOAZoass+FwEVLOnXf/vB2LzzEMABDeon1mX9y0GDnr04/4uIKxHtoWUyONSaxPdguis 10+JsyEq6b+gegzNLK9jyUSS9ABsw4lQNzRXPoi7YnTH7jzOjBjeBeFkRGu0qOpRmBms tyXw== 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=oc1Y4NMhbCVXiBqEN7io2NrC3w9YKQLRDFoQx1B3ae0=; b=pLbfoCVPvpVxcZTXYyBNbRkyRGuNSPmHzZ2P5HX0vTSenKFXBLKFMyFo3C0PhAPCkI 65eP/HDACbcGAnUVmhrjIAaCHxbU7596HKFGOQjUBkdryfwHnuaPOph7dEgAWshzrWxZ EEC/EVI1+lOVEM/FzOvpH7eiSXRcZFszE9yTZm94+P9hlcCrOfq+e+5jAQ0lLpdtgGOF z+CTxbISztra5PjfOY3NEnMAKx1AzPvNWyDbt82oVCbGuhvq3VOtPNWxIoSIDYed7IjK fkdTh5v0s/234ZR5IRsy2tLSbYSV3pGoGgW9XAX//q43ZYWsuXBjxiVxrOU+BUjpICB2 79yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BRcBOxwn; 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 jj17si1263349ejc.372.2021.01.27.11.49.30; Wed, 27 Jan 2021 11:49:54 -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=BRcBOxwn; 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 S2391268AbhA0BkM (ORCPT + 99 others); Tue, 26 Jan 2021 20:40:12 -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-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 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/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 */ -- 2.25.1