All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC]: can-next 2021-04-06: peak_usb cleanups
@ 2021-04-06 11:16 Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 01/10] can: peak_usb: fix checkpatch warnings Marc Kleine-Budde
                   ` (11 more replies)
  0 siblings, 12 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean

Hello,

this series consist of several cleanups for the peak_usb driver. It
was tested on the peak_usb_fd, but it also does some changes on the
peak_usb, which I don't have access to.

Please test.

regards,
Marc




^ permalink raw reply	[flat|nested] 14+ messages in thread

* [can-next-rfc 01/10] can: peak_usb: fix checkpatch warnings
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 02/10] can: peak_usb: pcan_usb_pro.h: remove double space in indention Marc Kleine-Budde
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

This patch cleans several checkpatch warnings in the peak_usb driver.

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c      | 4 ++--
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 1 +
 drivers/net/can/usb/peak_usb/pcan_usb_core.h | 2 +-
 drivers/net/can/usb/peak_usb/pcan_usb_pro.c  | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index ba509aed7b4c..e23049c81159 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -401,7 +401,7 @@ static int pcan_usb_update_ts(struct pcan_usb_msg_context *mc)
 {
 	__le16 tmp16;
 
-	if ((mc->ptr+2) > mc->end)
+	if ((mc->ptr + 2) > mc->end)
 		return -EINVAL;
 
 	memcpy(&tmp16, mc->ptr, 2);
@@ -1039,7 +1039,7 @@ const struct peak_usb_adapter pcan_usb = {
 			      CAN_CTRLMODE_BERR_REPORTING |
 			      CAN_CTRLMODE_CC_LEN8_DLC,
 	.clock = {
-		.freq = PCAN_USB_CRYSTAL_HZ / 2 ,
+		.freq = PCAN_USB_CRYSTAL_HZ / 2,
 	},
 	.bittiming_const = &pcan_usb_const,
 
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index ad006edf474d..eccaf7fb3310 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -624,6 +624,7 @@ static int peak_usb_ndo_stop(struct net_device *netdev)
 	/* can set bus off now */
 	if (dev->adapter->dev_set_bus) {
 		int err = dev->adapter->dev_set_bus(dev, 0);
+
 		if (err)
 			return err;
 	}
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
index e15b4c78f309..59afe880a481 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
@@ -31,7 +31,7 @@
 /* usb adapters maximum channels per usb interface */
 #define PCAN_USB_MAX_CHANNEL		2
 
-/* maximum length of the usb commands sent to/received from  the devices */
+/* maximum length of the usb commands sent to/received from the devices */
 #define PCAN_USB_MAX_CMD_LEN		32
 
 struct peak_usb_device;
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
index 2d1b645af76c..ecb08359f719 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
@@ -290,7 +290,7 @@ static int pcan_usb_pro_wait_rsp(struct peak_usb_device *dev,
 					   pr->data_type);
 
 			/* check if channel in response corresponds too */
-			else if ((req_channel != 0xff) && \
+			else if ((req_channel != 0xff) &&
 				(pr->bus_act.channel != req_channel))
 				netdev_err(dev->netdev,
 					"got rsp %xh but on chan%u: ignored\n",

base-commit: cc0626c2aaed8e475efdd85fa374b497a7192e35
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [can-next-rfc 02/10] can: peak_usb: pcan_usb_pro.h: remove double space in indention
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 01/10] can: peak_usb: fix checkpatch warnings Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 03/10] can: peak_usb: remove unused variables from struct peak_usb_device Marc Kleine-Budde
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

This patch replaces the double space indention after the u8 with a
single space in pcan_usb_pro.h.

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb_pro.h | 76 ++++++++++-----------
 1 file changed, 38 insertions(+), 38 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.h b/drivers/net/can/usb/peak_usb/pcan_usb_pro.h
index 6f4504300e23..5d4cf14eb9d9 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.h
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.h
@@ -34,11 +34,11 @@
 /* PCAN_USBPRO_INFO_BL vendor request record type */
 struct __packed pcan_usb_pro_blinfo {
 	__le32 ctrl_type;
-	u8  version[4];
-	u8  day;
-	u8  month;
-	u8  year;
-	u8  dummy;
+	u8 version[4];
+	u8 day;
+	u8 month;
+	u8 year;
+	u8 dummy;
 	__le32 serial_num_hi;
 	__le32 serial_num_lo;
 	__le32 hw_type;
@@ -48,11 +48,11 @@ struct __packed pcan_usb_pro_blinfo {
 /* PCAN_USBPRO_INFO_FW vendor request record type */
 struct __packed pcan_usb_pro_fwinfo {
 	__le32 ctrl_type;
-	u8  version[4];
-	u8  day;
-	u8  month;
-	u8  year;
-	u8  dummy;
+	u8 version[4];
+	u8 day;
+	u8 month;
+	u8 year;
+	u8 dummy;
 	__le32 fw_type;
 };
 
@@ -78,39 +78,39 @@ struct __packed pcan_usb_pro_fwinfo {
 
 /* record structures */
 struct __packed pcan_usb_pro_btr {
-	u8  data_type;
-	u8  channel;
+	u8 data_type;
+	u8 channel;
 	__le16 dummy;
 	__le32 CCBT;
 };
 
 struct __packed pcan_usb_pro_busact {
-	u8  data_type;
-	u8  channel;
+	u8 data_type;
+	u8 channel;
 	__le16 onoff;
 };
 
 struct __packed pcan_usb_pro_silent {
-	u8  data_type;
-	u8  channel;
+	u8 data_type;
+	u8 channel;
 	__le16 onoff;
 };
 
 struct __packed pcan_usb_pro_filter {
-	u8  data_type;
-	u8  dummy;
+	u8 data_type;
+	u8 dummy;
 	__le16 filter_mode;
 };
 
 struct __packed pcan_usb_pro_setts {
-	u8  data_type;
-	u8  dummy;
+	u8 data_type;
+	u8 dummy;
 	__le16 mode;
 };
 
 struct __packed pcan_usb_pro_devid {
-	u8  data_type;
-	u8  channel;
+	u8 data_type;
+	u8 channel;
 	__le16 dummy;
 	__le32 serial_num;
 };
@@ -122,21 +122,21 @@ struct __packed pcan_usb_pro_devid {
 #define PCAN_USBPRO_LED_OFF		0x04
 
 struct __packed pcan_usb_pro_setled {
-	u8  data_type;
-	u8  channel;
+	u8 data_type;
+	u8 channel;
 	__le16 mode;
 	__le32 timeout;
 };
 
 struct __packed pcan_usb_pro_rxmsg {
-	u8  data_type;
-	u8  client;
-	u8  flags;
-	u8  len;
+	u8 data_type;
+	u8 client;
+	u8 flags;
+	u8 len;
 	__le32 ts32;
 	__le32 id;
 
-	u8  data[8];
+	u8 data[8];
 };
 
 #define PCAN_USBPRO_STATUS_ERROR	0x0001
@@ -145,26 +145,26 @@ struct __packed pcan_usb_pro_rxmsg {
 #define PCAN_USBPRO_STATUS_QOVERRUN	0x0008
 
 struct __packed pcan_usb_pro_rxstatus {
-	u8  data_type;
-	u8  channel;
+	u8 data_type;
+	u8 channel;
 	__le16 status;
 	__le32 ts32;
 	__le32 err_frm;
 };
 
 struct __packed pcan_usb_pro_rxts {
-	u8  data_type;
-	u8  dummy[3];
+	u8 data_type;
+	u8 dummy[3];
 	__le32 ts64[2];
 };
 
 struct __packed pcan_usb_pro_txmsg {
-	u8  data_type;
-	u8  client;
-	u8  flags;
-	u8  len;
+	u8 data_type;
+	u8 client;
+	u8 flags;
+	u8 len;
 	__le32 id;
-	u8  data[8];
+	u8 data[8];
 };
 
 union pcan_usb_pro_rec {
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [can-next-rfc 03/10] can: peak_usb: remove unused variables from struct peak_usb_device
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 01/10] can: peak_usb: fix checkpatch warnings Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 02/10] can: peak_usb: pcan_usb_pro.h: remove double space in indention Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 04/10] can: peak_usb: remove write only variable struct peak_usb_adapter::ts_period Marc Kleine-Budde
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

This patch removes the unused variables struct
peak_usb_device::echo_skb and struct peak_usb_device::bus_load from
the driver.

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
index 59afe880a481..64c4c22bb296 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
@@ -114,8 +114,6 @@ struct peak_usb_device {
 	unsigned int ctrl_idx;
 	u32 state;
 
-	struct sk_buff *echo_skb[PCAN_USB_MAX_TX_URBS];
-
 	struct usb_device *udev;
 	struct net_device *netdev;
 
@@ -132,8 +130,6 @@ struct peak_usb_device {
 	u8 ep_msg_in;
 	u8 ep_msg_out;
 
-	u16 bus_load;
-
 	struct peak_usb_device *prev_siblings;
 	struct peak_usb_device *next_siblings;
 };
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [can-next-rfc 04/10] can: peak_usb: remove write only variable struct peak_usb_adapter::ts_period
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2021-04-06 11:16 ` [can-next-rfc 03/10] can: peak_usb: remove unused variables from struct peak_usb_device Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 05/10] can: peak_usb: peak_usb_probe(): make use of driver_info Marc Kleine-Budde
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

The variable struct peak_usb_adapter::ts_period is only ever written
to. This patch removes it from the driver.

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c      | 1 -
 drivers/net/can/usb/peak_usb/pcan_usb_core.h | 1 -
 drivers/net/can/usb/peak_usb/pcan_usb_fd.c   | 4 ----
 drivers/net/can/usb/peak_usb/pcan_usb_pro.c  | 1 -
 4 files changed, 7 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index e23049c81159..38bee69ff48a 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -1050,7 +1050,6 @@ const struct peak_usb_adapter pcan_usb = {
 
 	/* timestamps usage */
 	.ts_used_bits = 16,
-	.ts_period = 24575, /* calibration period in ts. */
 	.us_per_ts_scale = PCAN_USB_TS_US_PER_TICK, /* us=(ts*scale) */
 	.us_per_ts_shift = PCAN_USB_TS_DIV_SHIFTER, /*  >> shift     */
 
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
index 64c4c22bb296..b00a4811bf61 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
@@ -73,7 +73,6 @@ struct peak_usb_adapter {
 	u8 ep_msg_in;
 	u8 ep_msg_out[PCAN_USB_MAX_CHANNEL];
 	u8 ts_used_bits;
-	u32 ts_period;
 	u8 us_per_ts_shift;
 	u32 us_per_ts_scale;
 
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
index 6f62b6f51051..b11eabad575b 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
@@ -1081,7 +1081,6 @@ const struct peak_usb_adapter pcan_usb_fd = {
 
 	/* timestamps usage */
 	.ts_used_bits = 32,
-	.ts_period = 1000000, /* calibration period in ts. */
 	.us_per_ts_scale = 1, /* us = (ts * scale) >> shift */
 	.us_per_ts_shift = 0,
 
@@ -1156,7 +1155,6 @@ const struct peak_usb_adapter pcan_usb_chip = {
 
 	/* timestamps usage */
 	.ts_used_bits = 32,
-	.ts_period = 1000000, /* calibration period in ts. */
 	.us_per_ts_scale = 1, /* us = (ts * scale) >> shift */
 	.us_per_ts_shift = 0,
 
@@ -1231,7 +1229,6 @@ const struct peak_usb_adapter pcan_usb_pro_fd = {
 
 	/* timestamps usage */
 	.ts_used_bits = 32,
-	.ts_period = 1000000, /* calibration period in ts. */
 	.us_per_ts_scale = 1, /* us = (ts * scale) >> shift */
 	.us_per_ts_shift = 0,
 
@@ -1306,7 +1303,6 @@ const struct peak_usb_adapter pcan_usb_x6 = {
 
 	/* timestamps usage */
 	.ts_used_bits = 32,
-	.ts_period = 1000000, /* calibration period in ts. */
 	.us_per_ts_scale = 1, /* us = (ts * scale) >> shift */
 	.us_per_ts_shift = 0,
 
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
index ecb08359f719..589ba797fb33 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
@@ -1058,7 +1058,6 @@ const struct peak_usb_adapter pcan_usb_pro = {
 
 	/* timestamps usage */
 	.ts_used_bits = 32,
-	.ts_period = 1000000, /* calibration period in ts. */
 	.us_per_ts_scale = 1, /* us = (ts * scale) >> shift */
 	.us_per_ts_shift = 0,
 
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [can-next-rfc 05/10] can: peak_usb: peak_usb_probe(): make use of driver_info
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2021-04-06 11:16 ` [can-next-rfc 04/10] can: peak_usb: remove write only variable struct peak_usb_adapter::ts_period Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 06/10] can: peak_usb: pcan_usb_{,pro}_get_device_id(): remove unneeded check for device_id Marc Kleine-Budde
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

There's no need to iterate over all supported adapters to find the
struct peak_usb_adapter that describes the currently probed devices's
capabilities. The driver core gives us the information for free, if we
assign it to the struct usb_device_id::driver_info.

This patch assigns the usb_device_id::driver_info and converts
peak_usb_probe() to make use of it. This reduces the driver size by
100 bytes on ARCH=arm.

| add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-124 (-124)
| Function                                     old     new   delta
| peak_usb_adapters_list                        24       -     -24
| peak_usb_probe                               236     136    -100
| Total: Before=25263, After=25139, chg -0.49%

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 57 +++++++++-----------
 1 file changed, 24 insertions(+), 33 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index eccaf7fb3310..4eea65aced8f 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -27,28 +27,32 @@ MODULE_DESCRIPTION("CAN driver for PEAK-System USB adapters");
 MODULE_LICENSE("GPL v2");
 
 /* Table of devices that work with this driver */
-static struct usb_device_id peak_usb_table[] = {
-	{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USB_PRODUCT_ID)},
-	{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPRO_PRODUCT_ID)},
-	{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBFD_PRODUCT_ID)},
-	{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPROFD_PRODUCT_ID)},
-	{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBCHIP_PRODUCT_ID)},
-	{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBX6_PRODUCT_ID)},
-	{} /* Terminating entry */
+static const struct usb_device_id peak_usb_table[] = {
+	{
+		USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USB_PRODUCT_ID),
+		.driver_info = (kernel_ulong_t)&pcan_usb,
+	}, {
+		USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPRO_PRODUCT_ID),
+		.driver_info = (kernel_ulong_t)&pcan_usb_pro,
+	}, {
+		USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBFD_PRODUCT_ID),
+		.driver_info = (kernel_ulong_t)&pcan_usb_fd,
+	}, {
+		USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPROFD_PRODUCT_ID),
+		.driver_info = (kernel_ulong_t)&pcan_usb_pro_fd,
+	}, {
+		USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBCHIP_PRODUCT_ID),
+		.driver_info = (kernel_ulong_t)&pcan_usb_chip,
+	}, {
+		USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBX6_PRODUCT_ID),
+		.driver_info = (kernel_ulong_t)&pcan_usb_x6,
+	}, {
+		/* Terminating entry */
+	}
 };
 
 MODULE_DEVICE_TABLE(usb, peak_usb_table);
 
-/* List of supported PCAN-USB adapters (NULL terminated list) */
-static const struct peak_usb_adapter *const peak_usb_adapters_list[] = {
-	&pcan_usb,
-	&pcan_usb_pro,
-	&pcan_usb_fd,
-	&pcan_usb_pro_fd,
-	&pcan_usb_chip,
-	&pcan_usb_x6,
-};
-
 /*
  * dump memory
  */
@@ -924,24 +928,11 @@ static void peak_usb_disconnect(struct usb_interface *intf)
 static int peak_usb_probe(struct usb_interface *intf,
 			  const struct usb_device_id *id)
 {
-	struct usb_device *usb_dev = interface_to_usbdev(intf);
-	const u16 usb_id_product = le16_to_cpu(usb_dev->descriptor.idProduct);
-	const struct peak_usb_adapter *peak_usb_adapter = NULL;
+	const struct peak_usb_adapter *peak_usb_adapter;
 	int i, err = -ENOMEM;
 
 	/* get corresponding PCAN-USB adapter */
-	for (i = 0; i < ARRAY_SIZE(peak_usb_adapters_list); i++)
-		if (peak_usb_adapters_list[i]->device_id == usb_id_product) {
-			peak_usb_adapter = peak_usb_adapters_list[i];
-			break;
-		}
-
-	if (!peak_usb_adapter) {
-		/* should never come except device_id bad usage in this file */
-		pr_err("%s: didn't find device id. 0x%x in devices list\n",
-			PCAN_USB_DRIVER_NAME, usb_id_product);
-		return -ENODEV;
-	}
+	peak_usb_adapter = (const struct peak_usb_adapter *)id->driver_info;
 
 	/* got corresponding adapter: check if it handles current interface */
 	if (peak_usb_adapter->intf_probe) {
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [can-next-rfc 06/10] can: peak_usb: pcan_usb_{,pro}_get_device_id(): remove unneeded check for device_id
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
                   ` (4 preceding siblings ...)
  2021-04-06 11:16 ` [can-next-rfc 05/10] can: peak_usb: peak_usb_probe(): make use of driver_info Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 07/10] can: peak_usb: pcan_usb_get_serial(): remove error message from error path Marc Kleine-Budde
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

The callback struct peak_usb_adapter::dev_get_device_id, which is
implemented by the functions pcan_usb_{,pro}_get_device_id() is only
ever called with a valid device_id pointer.

This patch removes the unneeded check if the device_id pointer is
valid.

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c     | 4 ++--
 drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index 38bee69ff48a..671d589b48c1 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -388,8 +388,8 @@ static int pcan_usb_get_device_id(struct peak_usb_device *dev, u32 *device_id)
 	err = pcan_usb_wait_rsp(dev, PCAN_USB_CMD_DEVID, PCAN_USB_GET, args);
 	if (err)
 		netdev_err(dev->netdev, "getting device id failure: %d\n", err);
-	else if (device_id)
-		*device_id = args[0];
+
+	*device_id = args[0];
 
 	return err;
 }
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
index 589ba797fb33..858ab22708fc 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
@@ -439,8 +439,7 @@ static int pcan_usb_pro_get_device_id(struct peak_usb_device *dev,
 		return err;
 
 	pdn = (struct pcan_usb_pro_devid *)pc;
-	if (device_id)
-		*device_id = le32_to_cpu(pdn->serial_num);
+	*device_id = le32_to_cpu(pdn->serial_num);
 
 	return err;
 }
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [can-next-rfc 07/10] can: peak_usb: pcan_usb_get_serial(): remove error message from error path
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
                   ` (5 preceding siblings ...)
  2021-04-06 11:16 ` [can-next-rfc 06/10] can: peak_usb: pcan_usb_{,pro}_get_device_id(): remove unneeded check for device_id Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 08/10] can: peak_usb: pcan_usb_get_serial(): make use of le32_to_cpup() Marc Kleine-Budde
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

The caller of pcan_usb_get_serial() already prints an error message,
so remove this one and return immediately.

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index 671d589b48c1..fd5ea95fd55d 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -365,16 +365,17 @@ static int pcan_usb_get_serial(struct peak_usb_device *dev, u32 *serial_number)
 	int err;
 
 	err = pcan_usb_wait_rsp(dev, PCAN_USB_CMD_SN, PCAN_USB_GET, args);
-	if (err) {
-		netdev_err(dev->netdev, "getting serial failure: %d\n", err);
-	} else if (serial_number) {
+	if (err)
+		return err;
+
+	if (serial_number) {
 		__le32 tmp32;
 
 		memcpy(&tmp32, args, 4);
 		*serial_number = le32_to_cpu(tmp32);
 	}
 
-	return err;
+	return 0;
 }
 
 /*
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [can-next-rfc 08/10] can: peak_usb: pcan_usb_get_serial(): make use of le32_to_cpup()
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
                   ` (6 preceding siblings ...)
  2021-04-06 11:16 ` [can-next-rfc 07/10] can: peak_usb: pcan_usb_get_serial(): remove error message from error path Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 09/10] can: peak_usb: pcan_usb_get_serial(): unconditionally assign serial_number Marc Kleine-Budde
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

This patch replaces the memcpy() + le32_to_cpu() by le32_to_cpup().

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index fd5ea95fd55d..ffb01c3a3827 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -368,12 +368,8 @@ static int pcan_usb_get_serial(struct peak_usb_device *dev, u32 *serial_number)
 	if (err)
 		return err;
 
-	if (serial_number) {
-		__le32 tmp32;
-
-		memcpy(&tmp32, args, 4);
-		*serial_number = le32_to_cpu(tmp32);
-	}
+	if (serial_number)
+		*serial_number = le32_to_cpup((__le32 *)args);
 
 	return 0;
 }
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [can-next-rfc 09/10] can: peak_usb: pcan_usb_get_serial(): unconditionally assign serial_number
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
                   ` (7 preceding siblings ...)
  2021-04-06 11:16 ` [can-next-rfc 08/10] can: peak_usb: pcan_usb_get_serial(): make use of le32_to_cpup() Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-06 11:16 ` [can-next-rfc 10/10] can: peak_usb: pcan_usb: replace open coded endianness conversion of unaligned data Marc Kleine-Budde
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

The function serial_number is only called from one location with a
valid serial_number pointer. Remove not needed NULL pointer check.

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index ffb01c3a3827..929cc1b05aa2 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -367,9 +367,7 @@ static int pcan_usb_get_serial(struct peak_usb_device *dev, u32 *serial_number)
 	err = pcan_usb_wait_rsp(dev, PCAN_USB_CMD_SN, PCAN_USB_GET, args);
 	if (err)
 		return err;
-
-	if (serial_number)
-		*serial_number = le32_to_cpup((__le32 *)args);
+	*serial_number = le32_to_cpup((__le32 *)args);
 
 	return 0;
 }
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [can-next-rfc 10/10] can: peak_usb: pcan_usb: replace open coded endianness conversion of unaligned data
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
                   ` (8 preceding siblings ...)
  2021-04-06 11:16 ` [can-next-rfc 09/10] can: peak_usb: pcan_usb_get_serial(): unconditionally assign serial_number Marc Kleine-Budde
@ 2021-04-06 11:16 ` Marc Kleine-Budde
  2021-04-12  9:39 ` [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
  2021-04-12 10:45 ` Stéphane Grosjean
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-06 11:16 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean, Marc Kleine-Budde

This patch replaces the open coded endianness conversion of unaligned
data by the appropriate get/put_unaligned_leXX() variants.

Cc: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c | 37 ++++++++-----------------
 1 file changed, 11 insertions(+), 26 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index 929cc1b05aa2..1d6f77252f01 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -394,14 +394,10 @@ static int pcan_usb_get_device_id(struct peak_usb_device *dev, u32 *device_id)
  */
 static int pcan_usb_update_ts(struct pcan_usb_msg_context *mc)
 {
-	__le16 tmp16;
-
 	if ((mc->ptr + 2) > mc->end)
 		return -EINVAL;
 
-	memcpy(&tmp16, mc->ptr, 2);
-
-	mc->ts16 = le16_to_cpu(tmp16);
+	mc->ts16 = get_unaligned_le16(mc->ptr);
 
 	if (mc->rec_idx > 0)
 		peak_usb_update_ts_now(&mc->pdev->time_ref, mc->ts16);
@@ -418,16 +414,13 @@ static int pcan_usb_decode_ts(struct pcan_usb_msg_context *mc, u8 first_packet)
 {
 	/* only 1st packet supplies a word timestamp */
 	if (first_packet) {
-		__le16 tmp16;
-
 		if ((mc->ptr + 2) > mc->end)
 			return -EINVAL;
 
-		memcpy(&tmp16, mc->ptr, 2);
-		mc->ptr += 2;
-
-		mc->ts16 = le16_to_cpu(tmp16);
+		mc->ts16 = get_unaligned_le16(mc->ptr);
 		mc->prev_ts8 = mc->ts16 & 0x00ff;
+
+		mc->ptr += 2;
 	} else {
 		u8 ts8;
 
@@ -717,25 +710,17 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)
 		return -ENOMEM;
 
 	if (status_len & PCAN_USB_STATUSLEN_EXT_ID) {
-		__le32 tmp32;
-
 		if ((mc->ptr + 4) > mc->end)
 			goto decode_failed;
 
-		memcpy(&tmp32, mc->ptr, 4);
+		cf->can_id = get_unaligned_le32(mc->ptr) >> 3 | CAN_EFF_FLAG;
 		mc->ptr += 4;
-
-		cf->can_id = (le32_to_cpu(tmp32) >> 3) | CAN_EFF_FLAG;
 	} else {
-		__le16 tmp16;
-
 		if ((mc->ptr + 2) > mc->end)
 			goto decode_failed;
 
-		memcpy(&tmp16, mc->ptr, 2);
+		cf->can_id = get_unaligned_le16(mc->ptr) >> 5;
 		mc->ptr += 2;
-
-		cf->can_id = le16_to_cpu(tmp16) >> 5;
 	}
 
 	can_frame_set_cc_len(cf, rec_len, mc->pdev->dev.can.ctrlmode);
@@ -849,15 +834,15 @@ static int pcan_usb_encode_msg(struct peak_usb_device *dev, struct sk_buff *skb,
 
 	/* can id */
 	if (cf->can_id & CAN_EFF_FLAG) {
-		__le32 tmp32 = cpu_to_le32((cf->can_id & CAN_ERR_MASK) << 3);
-
 		*pc |= PCAN_USB_STATUSLEN_EXT_ID;
-		memcpy(++pc, &tmp32, 4);
+		pc++;
+
+		put_unaligned_le32((cf->can_id & CAN_ERR_MASK) << 3, pc);
 		pc += 4;
 	} else {
-		__le16 tmp16 = cpu_to_le16((cf->can_id & CAN_ERR_MASK) << 5);
+		pc++;
 
-		memcpy(++pc, &tmp16, 2);
+		put_unaligned_le16((cf->can_id & CAN_ERR_MASK) << 5, pc);
 		pc += 2;
 	}
 
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [RFC]: can-next 2021-04-06: peak_usb cleanups
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
                   ` (9 preceding siblings ...)
  2021-04-06 11:16 ` [can-next-rfc 10/10] can: peak_usb: pcan_usb: replace open coded endianness conversion of unaligned data Marc Kleine-Budde
@ 2021-04-12  9:39 ` Marc Kleine-Budde
  2021-04-12 10:45 ` Stéphane Grosjean
  11 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-12  9:39 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Stephane Grosjean

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

On 06.04.2021 13:16:12, Marc Kleine-Budde wrote:
> this series consist of several cleanups for the peak_usb driver. It
> was tested on the peak_usb_fd, but it also does some changes on the
> peak_usb, which I don't have access to.

I'll include the patches 01...06 in my next pull request. I'd like the
others to be tested on real hardware, which I don't have.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [RFC]: can-next 2021-04-06: peak_usb cleanups
  2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
                   ` (10 preceding siblings ...)
  2021-04-12  9:39 ` [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
@ 2021-04-12 10:45 ` Stéphane Grosjean
  2021-04-12 11:03   ` Marc Kleine-Budde
  11 siblings, 1 reply; 14+ messages in thread
From: Stéphane Grosjean @ 2021-04-12 10:45 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: kernel, linux-can

Hello,

Thank you for your time and your work.

I've tested that serie of patches with all the CAN-FD USB interfaces from PEAK-System GmbH (that is, PCAN-USB FD, PCAN-USB Pro FD, PCAN-USB X6 and PCAN-Chip USB) as well as with the CAN 2.0 only USB interfaces PCAN-USB and PCAN-USB Pro, and I confirm all of them.

Do you need my Acked-by and/or Tested-by for each patch?

Regards,

--- Stéphane


De : Marc Kleine-Budde <mkl@pengutronix.de>
Envoyé : mardi 6 avril 2021 13:16
À : linux-can@vger.kernel.org <linux-can@vger.kernel.org>
Cc : kernel@pengutronix.de <kernel@pengutronix.de>; Stéphane Grosjean <s.grosjean@peak-system.com>
Objet : [RFC]: can-next 2021-04-06: peak_usb cleanups

Hello,

this series consist of several cleanups for the peak_usb driver. It
was tested on the peak_usb_fd, but it also does some changes on the
peak_usb, which I don't have access to.

Please test.

regards,
Marc



--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt - HRB 9183
Geschaeftsfuehrung: Alexander Gach / Uwe Wilhelm
Unsere Datenschutzerklaerung mit wichtigen Hinweisen
zur Behandlung personenbezogener Daten finden Sie unter
www.peak-system.com/Datenschutz.483.0.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [RFC]: can-next 2021-04-06: peak_usb cleanups
  2021-04-12 10:45 ` Stéphane Grosjean
@ 2021-04-12 11:03   ` Marc Kleine-Budde
  0 siblings, 0 replies; 14+ messages in thread
From: Marc Kleine-Budde @ 2021-04-12 11:03 UTC (permalink / raw)
  To: Stéphane Grosjean; +Cc: kernel, linux-can

[-- Attachment #1: Type: text/plain, Size: 779 bytes --]

On 12.04.2021 10:45:07, Stéphane Grosjean wrote:
> I've tested that serie of patches with all the CAN-FD USB interfaces
> from PEAK-System GmbH (that is, PCAN-USB FD, PCAN-USB Pro FD, PCAN-USB
> X6 and PCAN-Chip USB) as well as with the CAN 2.0 only USB interfaces
> PCAN-USB and PCAN-USB Pro, and I confirm all of them.

Thanks for testing!

> Do you need my Acked-by and/or Tested-by for each patch?

No need to, I can add them here. What should I add?
Acked-by?
Tested-by?

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-04-12 11:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-06 11:16 [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 01/10] can: peak_usb: fix checkpatch warnings Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 02/10] can: peak_usb: pcan_usb_pro.h: remove double space in indention Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 03/10] can: peak_usb: remove unused variables from struct peak_usb_device Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 04/10] can: peak_usb: remove write only variable struct peak_usb_adapter::ts_period Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 05/10] can: peak_usb: peak_usb_probe(): make use of driver_info Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 06/10] can: peak_usb: pcan_usb_{,pro}_get_device_id(): remove unneeded check for device_id Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 07/10] can: peak_usb: pcan_usb_get_serial(): remove error message from error path Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 08/10] can: peak_usb: pcan_usb_get_serial(): make use of le32_to_cpup() Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 09/10] can: peak_usb: pcan_usb_get_serial(): unconditionally assign serial_number Marc Kleine-Budde
2021-04-06 11:16 ` [can-next-rfc 10/10] can: peak_usb: pcan_usb: replace open coded endianness conversion of unaligned data Marc Kleine-Budde
2021-04-12  9:39 ` [RFC]: can-next 2021-04-06: peak_usb cleanups Marc Kleine-Budde
2021-04-12 10:45 ` Stéphane Grosjean
2021-04-12 11:03   ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.