can: peak_usb: peak_usb_probe(): make use of driver_info
authorMarc Kleine-Budde <mkl@pengutronix.de>
Mon, 5 Apr 2021 10:34:56 +0000 (12:34 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Tue, 13 Apr 2021 08:15:43 +0000 (10:15 +0200)
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%

Link: https://lore.kernel.org/r/20210406111622.1874957-6-mkl@pengutronix.de
Acked-by: Stephane Grosjean <s.grosjean@peak-system.com>
Tested-by: 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

index 7dff77a6ef70e2611342d0d25886ac769f456be9..e8f43ed90b7225ee9135136d33edc4b3e2beb88b 100644 (file)
@@ -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
  */
@@ -928,24 +932,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) {