Hi, while analyzing the comedi drivers, I noticed that quite a lot of them use a more or less similar find_boardinfo function. e.g.: cb_pcidas64.c static const struct pcidas64_board *cb_pcidas64_find_pci_board(struct pci_dev *pcidev) { unsigned int i; for (i = 0; i < ARRAY_SIZE(pcidas64_boards); i++) if (pcidev->device == pcidas64_boards[i].device_id) return &pcidas64_boards[i]; return NULL; } and ni_6527.c: static const struct ni6527_board * ni6527_find_boardinfo(struct pci_dev *pcidev) { unsigned int dev_id = pcidev->device; unsigned int n; for (n = 0; n < ARRAY_SIZE(ni6527_boards); n++) { const struct ni6527_board *board = &ni6527_boards[n]; if (board->dev_id == dev_id) return board; } return NULL; } The names and the exact implementation differ slightly, but in most cases it boils down to: unsigned int i; for (i = 0; i < ARRAY_SIZE(__BOARD_ARRAY__); i++) if (pcidev->device == __BOARD_ARRAY__[i].device_id) return &__BOARD_ARRAY__[i]; return NULL; unfortunately the __BOARD_ARRAY__ is always of a different type (but all contain the device_id field) and size. ---> is there a way to consolidate these functions into one function (which can operate on the different types) ? It's almost a bit like 'templates'. Maybe with some gcc extensions or kernel magic functions ? I already thought about passing a void pointer to the __BOARD_ARRAY__ and the size of one element of the __BOARD_ARRAY__ and doing pointer calculations - but I guess there must be a better way. Or is the only option to write a macro ? Looking forward to your replies. Thanks, Peter _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/devel