From nobody Thu Apr 2 07:30:17 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A0603BA232; Mon, 30 Mar 2026 10:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865903; cv=none; b=CrW+nCZLJ6yVgl2bOXtaMQ1z6zWAO4NbqO89dsSfoE3pn7lVKoO6jGGV6sWoPdMRom6YN5aPeSb3wKBCBQYQdmTMV4cFtV8poeyv240mGJYgaXC/x9hqm/WhiN2uepb6gqflhHxpnBP1xmnAbRWLVqXSzqkCEvHHzVU6iVT1xe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865903; c=relaxed/simple; bh=OIgIuyhycg9AXmBXj6mX65CWn51yo9SjxDiNniDBd+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ACWuOdtls/wrLKAX0tW0sMXTz4l5SSIJjUYmqAxnWZrol1VAkyfOvaqWwD6/Tts8Ufqsxx2pUEVmD/lp7eKGzQIKYhqRBSzuWMpMxLDU9lT7Vv8d1g0hpaTppV51he1vdU6hi1ysNh4JjReBJZ4872PI18SJpYCllU41xrct18o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sBTPxNDl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sBTPxNDl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BC0DC4AF0B; Mon, 30 Mar 2026 10:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774865903; bh=OIgIuyhycg9AXmBXj6mX65CWn51yo9SjxDiNniDBd+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sBTPxNDlhtMmxuPbMTogi6pg7bsxtCPg912fePUTWXdsBh7td1r1bgL67vgyLNOkM qvaK8kGVzKqJ1b6b5+Q9wYgAqnmsk8Mm3L0F8k5PdgsZDio6sXEN9Q1baqJMxf4q0V qn7nnjtD8v+e3BZZtezeF1fUwxHT8b0stEl6DKbZ5yqDIxmMHR0RW4TGv3UjeCjnsA UPX6ehun749hrSgwXmJ30rak/iqB3SVJWsggcdDImCh+gFk4FmLEVG5/6t621Qcxzo ED+bTgfJ/+PEd1fIQ1X2xj/8eQK1pJp9lzhxCmz43ot8ygyI5jyqBm3H6KH+gg5wuh 6k7s22UuF0a4A== Received: from johan by xi.lan with local (Exim 4.98.2) (envelope-from ) id 1w79hM-00000006z5g-3stD; Mon, 30 Mar 2026 12:18:20 +0200 From: Johan Hovold To: Marc Kleine-Budde , Vincent Mailhol Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 1/2] can: kvaser_usb: leaf: refactor endpoint lookup Date: Mon, 30 Mar 2026 12:18:16 +0200 Message-ID: <20260330101817.1664787-2-johan@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260330101817.1664787-1-johan@kernel.org> References: <20260330101817.1664787-1-johan@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the common USB helper for looking up bulk and interrupt endpoints instead of open coding. Signed-off-by: Johan Hovold --- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) 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 fd191ec5738b..df737cfc5ea0 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -1957,27 +1957,18 @@ static int kvaser_usb_leaf_get_berr_counter(const s= truct net_device *netdev, =20 static int kvaser_usb_leaf_setup_endpoints(struct kvaser_usb *dev) { - const struct usb_host_interface *iface_desc; - struct usb_endpoint_descriptor *endpoint; - int i; + struct usb_host_interface *iface_desc; + int ret; =20 iface_desc =3D dev->intf->cur_altsetting; =20 - for (i =3D 0; i < iface_desc->desc.bNumEndpoints; ++i) { - endpoint =3D &iface_desc->endpoint[i].desc; - - if (!dev->bulk_in && usb_endpoint_is_bulk_in(endpoint)) - dev->bulk_in =3D endpoint; - - if (!dev->bulk_out && usb_endpoint_is_bulk_out(endpoint)) - dev->bulk_out =3D endpoint; + /* use first bulk endpoint for in and out */ + ret =3D usb_find_common_endpoints(iface_desc, &dev->bulk_in, &dev->bulk_o= ut, + NULL, NULL); + if (ret) + return -ENODEV; =20 - /* use first bulk endpoint for in and out */ - if (dev->bulk_in && dev->bulk_out) - return 0; - } - - return -ENODEV; + return 0; } =20 const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops =3D { --=20 2.52.0 From nobody Thu Apr 2 07:30:17 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59FD33B637E; Mon, 30 Mar 2026 10:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865903; cv=none; b=Pgx6dfJp1lROZi3Wa+Y3HxO1mr4JFU+H7jWa8DjQgZRowFjLUeFbsXJTdFZPLwWkHREfFB9s3Y0plcp/c8Uxq6BtBRJsyAiQg4N0RZdEpb9+sHeYYrZ7wA3CjwVU6Siftdn3LYoVxP4fv+k38ZicMPij6rf5VTgVDLFJPBdDos4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774865903; c=relaxed/simple; bh=YEp7K+9nwXsbUVpe89cW8Su6LQFrRqXZD7MMhYUb2Cw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=exlpIR9dZzbbm7VACoHdoZ6uPLTl31L7upBHeIgBJvy10UtSwj4ndN1unZSHiFmdIk/oq8YBinBYHb39rPUWyo8M7hjTf27fmqlNUlbIBfQowY87C5o7O/b5VjQn3Dd0lE/HKLO6gS2evQzozYhKdCWq0rkcL4zLyllsqCInGpo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DFcEBP9B; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DFcEBP9B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08E92C4CEF7; Mon, 30 Mar 2026 10:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774865903; bh=YEp7K+9nwXsbUVpe89cW8Su6LQFrRqXZD7MMhYUb2Cw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DFcEBP9B5Lf4hKg2qyKOORVWYXyB9P0gdirACb/iiYIEXlme8T4v8wmV3w2YaBYgU P9mi9p0bDTV6p54KEPu4pSRzwDEO58yZulZFopm6lY7r2cmcgfPZYOozLp81B1wiVw nN5Zq5jMjM88iIwe6l29Yk/ycTl/U+WOR6HNJ6rWA0UQMhplXNmDvU4Jk8MXFFx4OZ aMuhCWfhJdEyZiRi5KO7nVbSE1cxw6NwWzA+bQ0ByNTBMMyney+8ZGj8iW4kEv7bz9 y9LKNHpTzOMUDR0Y4eHxtHFCsY+JqBbaAVn/Fgf62yTgnOa4ZrjDJLHQpI+zhoxpAV CUYGCRpXgIGRQ== Received: from johan by xi.lan with local (Exim 4.98.2) (envelope-from ) id 1w79hM-00000006z5i-3wJx; Mon, 30 Mar 2026 12:18:20 +0200 From: Johan Hovold To: Marc Kleine-Budde , Vincent Mailhol Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 2/2] can: ucan: refactor endpoint lookup Date: Mon, 30 Mar 2026 12:18:17 +0200 Message-ID: <20260330101817.1664787-3-johan@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260330101817.1664787-1-johan@kernel.org> References: <20260330101817.1664787-1-johan@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the common USB helpers for looking up bulk and interrupt endpoints (and determining endpoint numbers and max packet sizes) instead of open coding. Signed-off-by: Johan Hovold --- drivers/net/can/usb/ucan.c | 40 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c index ee3c1abbd063..f72e0644c5fd 100644 --- a/drivers/net/can/usb/ucan.c +++ b/drivers/net/can/usb/ucan.c @@ -1302,13 +1302,12 @@ static int ucan_probe(struct usb_interface *intf, const struct usb_device_id *id) { int ret; - int i; u32 protocol_version; struct usb_device *udev; struct net_device *netdev; struct usb_host_interface *iface_desc; struct ucan_priv *up; - struct usb_endpoint_descriptor *ep; + struct usb_endpoint_descriptor *ep_in, *ep_out; u16 in_ep_size; u16 out_ep_size; u8 in_ep_addr; @@ -1343,37 +1342,20 @@ static int ucan_probe(struct usb_interface *intf, } =20 /* check interface endpoints */ - in_ep_addr =3D 0; - out_ep_addr =3D 0; - in_ep_size =3D 0; - out_ep_size =3D 0; - for (i =3D 0; i < iface_desc->desc.bNumEndpoints; i++) { - ep =3D &iface_desc->endpoint[i].desc; - - if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) !=3D 0) && - ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) =3D=3D - USB_ENDPOINT_XFER_BULK)) { - /* In Endpoint */ - in_ep_addr =3D ep->bEndpointAddress; - in_ep_addr &=3D USB_ENDPOINT_NUMBER_MASK; - in_ep_size =3D le16_to_cpu(ep->wMaxPacketSize); - } else if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) =3D=3D - 0) && - ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) =3D=3D - USB_ENDPOINT_XFER_BULK)) { - /* Out Endpoint */ - out_ep_addr =3D ep->bEndpointAddress; - out_ep_addr &=3D USB_ENDPOINT_NUMBER_MASK; - out_ep_size =3D le16_to_cpu(ep->wMaxPacketSize); - } - } - - /* check if interface is sane */ - if (!in_ep_addr || !out_ep_addr) { + ret =3D usb_find_common_endpoints_reverse(iface_desc, &ep_in, &ep_out, + NULL, NULL); + if (ret) { dev_err(&udev->dev, "%s: invalid endpoint configuration\n", UCAN_DRIVER_NAME); goto err_firmware_needs_update; } + + in_ep_addr =3D usb_endpoint_num(ep_in); + out_ep_addr =3D usb_endpoint_num(ep_out); + in_ep_size =3D usb_endpoint_maxp(ep_in); + out_ep_size =3D usb_endpoint_maxp(ep_out); + + /* check if interface is sane */ if (in_ep_size < sizeof(struct ucan_message_in)) { dev_err(&udev->dev, "%s: invalid in_ep MaxPacketSize\n", UCAN_DRIVER_NAME); --=20 2.52.0