From patchwork Fri Dec 4 08:51:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 338211 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=-17.0 required=3.0 tests=BAYES_00, 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 1AF98C4361B for ; Fri, 4 Dec 2020 08:52:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC1CC227BF for ; Fri, 4 Dec 2020 08:52:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729278AbgLDIvo (ORCPT ); Fri, 4 Dec 2020 03:51:44 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:36130 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729242AbgLDIvo (ORCPT ); Fri, 4 Dec 2020 03:51:44 -0500 Received: by mail-lf1-f67.google.com with SMTP id v14so6634262lfo.3 for ; Fri, 04 Dec 2020 00:51:28 -0800 (PST) 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=5w0hnPaOEyit9bMPDiziBUhUR6rIaAP/djUPTNbCDHM=; b=Lqy9hJnXrIcJH2gqJDsAeCZ7QMRF0hZOqYIbY60av6UvREXtohnIS/rW7E+b538Iy4 O2IJO2sW2BFe8Z5YWIpTmAGvFKcDvAFo/wf7IJFOu+yl+E+mplFoP5CioEeIWZaIkOMQ hmQY7LOagaHaE5ufy7vCPZWSkoH9FeltxJT5oBtOqsB1hPhcegNRdm6mTI/d+4lhi8Zv e4wMRASCnfbHVzwGqDH/UTjn3X47h+e0pBytmptDmpCtwr+G8fAJ8jyQdF+pBaD/O9Ug 91wTjmKQ/2lsOtUZgBuP7UCWAMVyoGh58CpSnuK+xGeJELVbp/xgj5nKleNsYqhfyhr9 4O/A== X-Gm-Message-State: AOAM531F/wTsZ1F1ehHtvkl4IgHSGEIvd6R3ElVZRahlFaSsSx9NlK/w 4nKV1u5XdFP0n41LoooW46I= X-Google-Smtp-Source: ABdhPJx9tp/c1u3Oi+Tl0QxWR5wiVvQwIU27hm64cAdJpEp977ymTzIGoIxBwRcsH31dAHrXKx6Kjg== X-Received: by 2002:a19:ad6:: with SMTP id 205mr3047186lfk.522.1607071862532; Fri, 04 Dec 2020 00:51:02 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id m13sm1451599ljg.30.2020.12.04.00.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 00:51:01 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kl6oR-0005EN-1A; Fri, 04 Dec 2020 09:51:35 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Himadri Pandya , Johan Hovold Subject: [PATCH 1/3] USB: core: drop pipe-type check from new control-message helpers Date: Fri, 4 Dec 2020 09:51:08 +0100 Message-Id: <20201204085110.20055-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201204085110.20055-1-johan@kernel.org> References: <20201204085110.20055-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The new control-message helpers include a pipe-type check which is almost completely redundant. Control messages are generally sent to the default pipe which always exists and is of the correct type since its endpoint representation is created by USB core as part of enumeration for all devices. There is currently only one instance of a driver in the tree which use a control endpoint other than endpoint 0 (and it does not use the new helpers). Drivers should be testing for the existence of their resources at probe rather than at runtime, but to catch drivers failing to do so USB core already does a sanity check on URB submission and triggers a WARN(). Having the same sanity check done in the helper only suppresses the warning without allowing us to find and fix the drivers. Signed-off-by: Johan Hovold --- drivers/usb/core/message.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index c4e876050074..a04b01247117 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -204,9 +204,6 @@ int usb_control_msg_send(struct usb_device *dev, __u8 endpoint, __u8 request, int ret; u8 *data = NULL; - if (usb_pipe_type_check(dev, pipe)) - return -EINVAL; - if (size) { data = kmemdup(driver_data, size, memflags); if (!data) @@ -273,7 +270,7 @@ int usb_control_msg_recv(struct usb_device *dev, __u8 endpoint, __u8 request, int ret; u8 *data; - if (!size || !driver_data || usb_pipe_type_check(dev, pipe)) + if (!size || !driver_data) return -EINVAL; data = kmalloc(size, memflags); From patchwork Fri Dec 4 08:51:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 338210 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=-17.0 required=3.0 tests=BAYES_00, 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 7BD41C433FE for ; Fri, 4 Dec 2020 08:52:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21D0B22795 for ; Fri, 4 Dec 2020 08:52:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387488AbgLDIvq (ORCPT ); Fri, 4 Dec 2020 03:51:46 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:45538 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729244AbgLDIvp (ORCPT ); Fri, 4 Dec 2020 03:51:45 -0500 Received: by mail-lj1-f195.google.com with SMTP id q8so5667956ljc.12 for ; Fri, 04 Dec 2020 00:51:29 -0800 (PST) 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=bDXKraCZj9tEhUlYVZ7C8KxSuCwnY1NGnGNnV9ou2jU=; b=uoAvXOEMPKmesM9Gt6RqQHIurWGB/1PivDBOE+9cPdDhGpTgYHFzGSCsk0FF2kVFjy 3a7TcX7EjDSuIbaVr/oD3+DsT5SJffS3A3F3lXFxAYsRJYCNmJ7NHt91H1ofTx7N6PVA OC99gqLX9n2ilwwICekVA7IEVlEm3xaZOaXQizHk9sGp4qourkHzBKyQqxfQG4J7Y+sk msfdYKBplfAkpfabJukLstU2snIPPKu4nGds8GYpAk4vsWSyDAE7CXagFHmPVZjkjAVV ZHceXuxuI+R7DfL5n9klnbK28B0iVdMRkqwFsDtXcO0s+qZz7qPndrBJqObdwpc1t3Kl eqsA== X-Gm-Message-State: AOAM531e7rK74aBeTsRcuvW7yX2Yn/IwJUrE6dc0WBJ1g+7dPmzenfM/ EaWbKva0CzeCUqcDbPtis9w= X-Google-Smtp-Source: ABdhPJwzw3IGQwgxlpjLYzIMc8vDQ8iHWYIZl/jYhcmZ2DzwOOlnqlso2Gx9T37Uw4Gc8hMgJemSMw== X-Received: by 2002:a2e:9a88:: with SMTP id p8mr2976289lji.266.1607071863625; Fri, 04 Dec 2020 00:51:03 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id d18sm1444758ljo.49.2020.12.04.00.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 00:51:01 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kl6oR-0005EX-6y; Fri, 04 Dec 2020 09:51:35 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Himadri Pandya , Johan Hovold Subject: [PATCH 3/3] USB: core: return -EREMOTEIO on short usb_control_msg_recv() Date: Fri, 4 Dec 2020 09:51:10 +0100 Message-Id: <20201204085110.20055-4-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201204085110.20055-1-johan@kernel.org> References: <20201204085110.20055-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Return -EREMOTEIO instead of -EINVAL on short control transfers when using the new usb_control_msg_recv() helper. EINVAL is used to report invalid arguments (e.g. to the helper) and should not be used for unrelated errors. Many driver currently return -EIO on short control transfers but since host-controller drivers already use -EREMOTEIO for short transfers whenever the URB_SHORT_NOT_OK flag is set, let's use that here as well. This also allows usb_control_msg_recv() to eventually use URB_SHORT_NOT_OK without changing the return value again. Signed-off-by: Johan Hovold --- drivers/usb/core/message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index b08de9571f7a..30e9e680c74c 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -286,7 +286,7 @@ int usb_control_msg_recv(struct usb_device *dev, __u8 endpoint, __u8 request, memcpy(driver_data, data, size); ret = 0; } else { - ret = -EINVAL; + ret = -EREMOTEIO; } exit: