From patchwork Tue Dec 10 11:32:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11281921 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0000814BD for ; Tue, 10 Dec 2019 11:33:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC13220663 for ; Tue, 10 Dec 2019 11:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575977610; bh=lPiY+5yRrktmZ5oorkNKEb1I/fGjcTmLEn0mPG12tQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KOyQ3i/q1hy6ixW4UhWBzGtH8GLPRetKBLXTiGmbBLE2UO8sZtP/fA9VbkdNOvDfU k1OyYAt0H29XaQOSwwjTUcpoqwZlSdO/fhoeBZliqeDqynxxZZYhdL3Whg9PuxGg7G Oc2M3t/FLL/yiegg12CxknLIWJMyBWtWsJ7vbXyU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727398AbfLJLdZ (ORCPT ); Tue, 10 Dec 2019 06:33:25 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:36124 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727018AbfLJLdN (ORCPT ); Tue, 10 Dec 2019 06:33:13 -0500 Received: by mail-lj1-f193.google.com with SMTP id r19so19497582ljg.3; Tue, 10 Dec 2019 03:33:11 -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=sdMg7GZD86BDFhOalPKQ8m9kUAj6L4CkdcJA8F5jSmg=; b=fUDjACyVVa4QFiYFRAVdimnvGoPWdYxNl1mUgggPQkwJMGkPkTkGJPd8k2hWT33DYD KfOJ7/anhA6WRwXG2Vtc+mSUbMLjrcN6kXfOLy6MUIzjlpFcK3nF+qiZ/SJdX+zR8EBw vr9+SSV9Cv+Q7yHcj9UqgxrjRVB0igEYO/5i+fRFJK0yuPtAh3WxxN51bk47BOOyrJtt lYXUUnEInLYpZqzj1AAOfgv1KeMp7vN6oXf/5mU4QW7XCy+Bn3X/+joopNhcw+xy7uGt lB171MMuEeyeKYVnqd+F7WzJ4AxiZ/UYiEzv/AJLEbzcgaYPl8qw2HILBXPa71xBs+3z wRVA== X-Gm-Message-State: APjAAAVOfJrtZD+edOQNLzMnvSn50msfe+mHVufNr5MiTaGWP9OLT38i DfiQhY7/nZ1D6TaomTQ8hcc= X-Google-Smtp-Source: APXvYqwrdBxZkGkl3VYse6aA7Haf83fZOat6BiBhn798ugz4TFgmdQC7B11oA3wD4XNH+vQKAhhLnw== X-Received: by 2002:a2e:961a:: with SMTP id v26mr6001777ljh.185.1575977590895; Tue, 10 Dec 2019 03:33:10 -0800 (PST) Received: from xi.terra (c-14b8e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.184.20]) by smtp.gmail.com with ESMTPSA id c12sm1404031lfp.58.2019.12.10.03.33.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 03:33:09 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iedlQ-00010O-1Z; Tue, 10 Dec 2019 12:33:12 +0100 From: Johan Hovold To: Marc Kleine-Budde Cc: Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable , Jimmy Assarsson , Christer Beskow , Nicklas Johansson , Martin Henriksson Subject: [PATCH 1/2] can: kvaser_usb: fix interface sanity check Date: Tue, 10 Dec 2019 12:32:30 +0100 Message-Id: <20191210113231.3797-2-johan@kernel.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210113231.3797-1-johan@kernel.org> References: <20191210113231.3797-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure to use the current alternate setting when verifying the interface descriptors to avoid binding to an invalid interface. Failing to do so could cause the driver to misbehave or trigger a WARN() in usb_submit_urb() that kernels with panic_on_warn set would choke on. Fixes: aec5fb2268b7 ("can: kvaser_usb: Add support for Kvaser USB hydra family") Cc: stable # 4.19 Cc: Jimmy Assarsson Cc: Christer Beskow Cc: Nicklas Johansson Cc: Martin Henriksson Signed-off-by: Johan Hovold --- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 2 +- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c index 5fc0be564274..7ab87a758754 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c @@ -1590,7 +1590,7 @@ static int kvaser_usb_hydra_setup_endpoints(struct kvaser_usb *dev) struct usb_endpoint_descriptor *ep; int i; - iface_desc = &dev->intf->altsetting[0]; + iface_desc = dev->intf->cur_altsetting; for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { ep = &iface_desc->endpoint[i].desc; diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c index 07d2f3aa2c02..1c794bb443e1 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -1310,7 +1310,7 @@ static int kvaser_usb_leaf_setup_endpoints(struct kvaser_usb *dev) struct usb_endpoint_descriptor *endpoint; int i; - iface_desc = &dev->intf->altsetting[0]; + iface_desc = dev->intf->cur_altsetting; for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { endpoint = &iface_desc->endpoint[i].desc; From patchwork Tue Dec 10 11:32:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11281919 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A23B514BD for ; Tue, 10 Dec 2019 11:33:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8087320726 for ; Tue, 10 Dec 2019 11:33:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575977602; bh=4annv4BCWN8Ss8AD2TSC7cKl1pVZ+zcs+cJH7zUHP9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UDq7HneQ2jPIalX9Y3z0qPfA++tJDUSBp6EDmXTLAb8lT/TYviyYY6UVJl/NOBc44 /5zmvB617fyF0MBQADnX9fWgthWCfZbG7fjkjXoH5aetmryykyVDLCHdZhCyD8aloD i6bKGt1USWSGVLALOho03u+DeR58/4UUcr3KB65s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727340AbfLJLdQ (ORCPT ); Tue, 10 Dec 2019 06:33:16 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:32989 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727162AbfLJLdO (ORCPT ); Tue, 10 Dec 2019 06:33:14 -0500 Received: by mail-lj1-f194.google.com with SMTP id 21so19513288ljr.0; Tue, 10 Dec 2019 03:33:12 -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=Blqzm8+uJKvQuA0CbBCrZIVx4YR1ZVnP2Lq7em2cyqU=; b=uIsFRSpXYpbsB3qwKImibSBrF+IbCHbbPYNWQtRgjLODgQxa655ByJ9ezyf2/j/ePL sjmvkt6xMrhPZla7N3ceaPPA7OdaxogjLsFaH6rj5azn6TqPiYWpt1JbkE39GuLCscp4 F6ME7wD4sKmEyIj4wDaPpTBKTNT3naSvx9leKdDmhVll46Uu3Pwg6XjNyPkXbX/Ba4IP XwpfN4Jh3Dzw0zZQvXB3YOKMAHyqjQ27fV4ayNDXegz6v2G9VEXj8Bt42wHjbqH685MZ 0tVPetmJGl72xiI/XJDoiwH/IuzLdl5VlkF0OshrmhB80WT2X0d49iYo0AZjttu+Q81X GMbA== X-Gm-Message-State: APjAAAVjq8/iaM9dL03hCJLpo9s4QaXLpcBkIURWt8j0pC/v36X53eug pdvNwA35mn9G9UGdlHrrzoc= X-Google-Smtp-Source: APXvYqyIW5IfmyQIRr8p5hkGBqsmCvU2d723wr+Rta8PDZbIsTTmqLcYTIyuETrZVRpDC52t7Wr7qg== X-Received: by 2002:a2e:b0c9:: with SMTP id g9mr9586456ljl.134.1575977591464; Tue, 10 Dec 2019 03:33:11 -0800 (PST) Received: from xi.terra (c-14b8e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.184.20]) by smtp.gmail.com with ESMTPSA id i16sm1387353lfo.87.2019.12.10.03.33.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 03:33:09 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iedlQ-00010S-4r; Tue, 10 Dec 2019 12:33:12 +0100 From: Johan Hovold To: Marc Kleine-Budde Cc: Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 2/2] can: gs_usb: use descriptors of current altsetting Date: Tue, 10 Dec 2019 12:32:31 +0100 Message-Id: <20191210113231.3797-3-johan@kernel.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210113231.3797-1-johan@kernel.org> References: <20191210113231.3797-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure to always use the descriptors of the current alternate setting to avoid future issues when accessing fields that may differ between settings. Signed-off-by: Johan Hovold --- drivers/net/can/usb/gs_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index 2f74f6704c12..a4b4b742c80c 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -918,7 +918,7 @@ static int gs_usb_probe(struct usb_interface *intf, GS_USB_BREQ_HOST_FORMAT, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 1, - intf->altsetting[0].desc.bInterfaceNumber, + intf->cur_altsetting->desc.bInterfaceNumber, hconf, sizeof(*hconf), 1000); @@ -941,7 +941,7 @@ static int gs_usb_probe(struct usb_interface *intf, GS_USB_BREQ_DEVICE_CONFIG, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 1, - intf->altsetting[0].desc.bInterfaceNumber, + intf->cur_altsetting->desc.bInterfaceNumber, dconf, sizeof(*dconf), 1000);