Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

modpost: i2c aliases need no trailing wildcard

Not all device types need a wildcard at the end of their module
aliases. In particular, for i2c module aliases, the trailing wildcard
is not only unneeded, it could also cause the wrong driver to be
loaded.

As I2C devices have no IDs, i2c module aliases are simple, arbitrary
device names. For example:

$ /sbin/modinfo lm90
filename: /lib/modules/2.6.25-git18/kernel/drivers/hwmon/lm90.ko
author: Jean Delvare <khali@linux-fr.org>
description: LM90/ADM1032 driver
license: GPL
vermagic: 2.6.25-git18 mod_unload
depends: hwmon
alias: i2c:lm90*
alias: i2c:adm1032*
alias: i2c:lm99*
alias: i2c:lm86*
alias: i2c:max6657*
alias: i2c:adt7461*
alias: i2c:max6680*
$

This would cause trouble if one I2C chip name matches the beginning of
another I2C chip name and both chips are supported by different
drivers. For example, an i2c device named lm9042 would cause the lm90
driver to be loaded, while it doesn't support that device. This case
has yet to be seen in practice, but still, I'd like to fix it now. The
cleanest fix is to remove the trailing wildcard from i2c module aliases.

Here's a patch doing this.

Not all device type aliases need a trailing wildcard, in particular
the i2c aliases don't. Don't add a wildcard by default in do_table(),
instead let each device type handler add it if needed.

I have tested types acpi, dmi, eisa, i2c, ide, ieee1394, input, pci,
pcmcia, platform, pnp, scsi, serio, ssb and usb. Other types (ccw, of,
vio, parisc, sdio and virtio) are untested.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Jochen Friedrich <jochen@scram.de>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

authored by

Jean Delvare and committed by
Sam Ravnborg
ac551828 afa26be8

+26 -9
+26 -9
scripts/mod/file2alias.c
··· 51 51 sprintf(str + strlen(str), "*"); \ 52 52 } while(0) 53 53 54 + /* Always end in a wildcard, for future extension */ 55 + static inline void add_wildcard(char *str) 56 + { 57 + int len = strlen(str); 58 + 59 + if (str[len - 1] != '*') 60 + strcat(str + len, "*"); 61 + } 62 + 54 63 unsigned int cross_build = 0; 55 64 /** 56 65 * Check that sizeof(device_id type) are consistent with size of section ··· 142 133 id->match_flags&USB_DEVICE_ID_MATCH_INT_PROTOCOL, 143 134 id->bInterfaceProtocol); 144 135 145 - /* Always end in a wildcard, for future extension */ 146 - if (alias[strlen(alias)-1] != '*') 147 - strcat(alias, "*"); 136 + add_wildcard(alias); 148 137 buf_printf(&mod->dev_table_buf, 149 138 "MODULE_ALIAS(\"%s\");\n", alias); 150 139 } ··· 226 219 ADD(alias, "ver", id->match_flags & IEEE1394_MATCH_VERSION, 227 220 id->version); 228 221 222 + add_wildcard(alias); 229 223 return 1; 230 224 } 231 225 ··· 269 261 ADD(alias, "bc", baseclass_mask == 0xFF, baseclass); 270 262 ADD(alias, "sc", subclass_mask == 0xFF, subclass); 271 263 ADD(alias, "i", interface_mask == 0xFF, interface); 264 + add_wildcard(alias); 272 265 return 1; 273 266 } 274 267 ··· 292 283 id->dev_type); 293 284 ADD(alias, "dm", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_MODEL, 294 285 id->dev_model); 286 + add_wildcard(alias); 295 287 return 1; 296 288 } 297 289 ··· 300 290 static int do_ap_entry(const char *filename, 301 291 struct ap_device_id *id, char *alias) 302 292 { 303 - sprintf(alias, "ap:t%02X", id->dev_type); 293 + sprintf(alias, "ap:t%02X*", id->dev_type); 304 294 return 1; 305 295 } 306 296 ··· 319 309 ADD(alias, "id", id->id != SERIO_ANY, id->id); 320 310 ADD(alias, "ex", id->extra != SERIO_ANY, id->extra); 321 311 312 + add_wildcard(alias); 322 313 return 1; 323 314 } 324 315 ··· 327 316 static int do_acpi_entry(const char *filename, 328 317 struct acpi_device_id *id, char *alias) 329 318 { 330 - sprintf(alias, "acpi*:%s:", id->id); 319 + sprintf(alias, "acpi*:%s:*", id->id); 331 320 return 1; 332 321 } 333 322 ··· 335 324 static int do_pnp_entry(const char *filename, 336 325 struct pnp_device_id *id, char *alias) 337 326 { 338 - sprintf(alias, "pnp:d%s", id->id); 327 + sprintf(alias, "pnp:d%s*", id->id); 339 328 return 1; 340 329 } 341 330 ··· 420 409 ADD(alias, "pc", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, id->prod_id_hash[2]); 421 410 ADD(alias, "pd", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, id->prod_id_hash[3]); 422 411 412 + add_wildcard(alias); 423 413 return 1; 424 414 } 425 415 ··· 444 432 if (isspace (*tmp)) 445 433 *tmp = '_'; 446 434 435 + add_wildcard(alias); 447 436 return 1; 448 437 } 449 438 ··· 461 448 if (isspace (*tmp)) 462 449 *tmp = '_'; 463 450 451 + add_wildcard(alias); 464 452 return 1; 465 453 } 466 454 ··· 525 511 { 526 512 if (eisa->sig[0]) 527 513 sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", eisa->sig); 514 + else 515 + strcat(alias, "*"); 528 516 return 1; 529 517 } 530 518 ··· 545 529 ADD(alias, "rev", id->hversion_rev != PA_HVERSION_REV_ANY_ID, id->hversion_rev); 546 530 ADD(alias, "sv", id->sversion != PA_SVERSION_ANY_ID, id->sversion); 547 531 532 + add_wildcard(alias); 548 533 return 1; 549 534 } 550 535 ··· 561 544 ADD(alias, "c", id->class != (__u8)SDIO_ANY_ID, id->class); 562 545 ADD(alias, "v", id->vendor != (__u16)SDIO_ANY_ID, id->vendor); 563 546 ADD(alias, "d", id->device != (__u16)SDIO_ANY_ID, id->device); 547 + add_wildcard(alias); 564 548 return 1; 565 549 } 566 550 ··· 577 559 ADD(alias, "v", id->vendor != SSB_ANY_VENDOR, id->vendor); 578 560 ADD(alias, "id", id->coreid != SSB_ANY_ID, id->coreid); 579 561 ADD(alias, "rev", id->revision != SSB_ANY_REV, id->revision); 562 + add_wildcard(alias); 580 563 return 1; 581 564 } 582 565 ··· 592 573 ADD(alias, "d", 1, id->device); 593 574 ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor); 594 575 576 + add_wildcard(alias); 595 577 return 1; 596 578 } 597 579 ··· 632 612 633 613 for (i = 0; i < size; i += id_size) { 634 614 if (do_entry(mod->name, symval+i, alias)) { 635 - /* Always end in a wildcard, for future extension */ 636 - if (alias[strlen(alias)-1] != '*') 637 - strcat(alias, "*"); 638 615 buf_printf(&mod->dev_table_buf, 639 616 "MODULE_ALIAS(\"%s\");\n", alias); 640 617 }