Skip to contentSkip to conversation

can: peak_usb: use ARRAY_SIZE instead off NULL termination for peak_usb_adapters_list

PATCH Stéphane Grosjean 2 participants 2 messages Jan 27, 2015 CAN network drivers

lore
Share & tools
lore
#0 lore raw

Hi Mark,

You've got my Ack for this patch.

Thanks,

Quoted 48 lines · Marc Kleine-Budde

This patch converts the list "static struct peak_usb_adapter *peak_usb_adapters_list[]" to be used with ARRAY_SIZE not with a NULL termination, as the size is known during compile time.

---
drivers/net/can/usb/peak_usb/pcan_usb_core.c | 10 +++++-----

1 file changed, 5 insertions(+), 5 deletions(-) 
drivers/net/can/usb/peak_usb/pcan_usb_core.c +5 -5
index c62f48a1161d..26c0cc3ce3b2 100644 
@@ -46,7 +46,6 @@ MODULE_DEVICE_TABLE(usb, peak_usb_table); 
 static struct peak_usb_adapter *peak_usb_adapters_list[] = { 
 &pcan_usb, 
 &pcan_usb_pro, 
- NULL, 
 }; 
 
 /* 
@@ -857,17 +856,18 @@ static int peak_usb_probe(struct usb_interface *intf, 
 { 
 struct usb_device *usb_dev = interface_to_usbdev(intf); 
 const u16 usb_id_product = le16_to_cpu(usb_dev->descriptor.idProduct); 
- struct peak_usb_adapter *peak_usb_adapter, **pp; 
+ struct peak_usb_adapter *peak_usb_adapter = NULL; 
 int i, err = -ENOMEM; 
 
 usb_dev = interface_to_usbdev(intf); 
 
 /* get corresponding PCAN-USB adapter */ 
- for (pp = peak_usb_adapters_list; *pp; pp++) 
- if ((*pp)->device_id == usb_id_product) 
+ 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; 
+ } 
 
- peak_usb_adapter = *pp; 
 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", 
Signature · 1 line
2.1.4 

--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt
Handelsregister Darmstadt HRB 9183
Geschaeftsfuehrung: Alexander Gach, Uwe Wilhelm
--

#1 lore raw
Quoted 3 lines · Stéphane Grosjean

Hi Mark,

You've got my Ack for this patch.

Thanks,
Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |