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

Configure Feed

Select the types of activity you want to include in your feed.

net: phy: simplify PHY fixup registration

Based on the fact that either bus_id-based matching or phy_uid-based
matching is used, the code can be simplified. PHY_ANY_ID and
PHY_ANY_UID are not needed. Ensure that phy_id_compare() is called
only if phy_uid_mask isn't zero, because a zero value would always
result in a match.
In addition change the return value type of phy_needs_fixup() to bool.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Link: https://patch.msgid.link/e7394cc8-5895-4d02-a8fe-802345c7c547@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Heiner Kallweit and committed by
Jakub Kicinski
0d035fb5 1be080b7

+13 -21
+13 -21
drivers/net/phy/phy_device.c
··· 49 49 MODULE_AUTHOR("Andy Fleming"); 50 50 MODULE_LICENSE("GPL"); 51 51 52 - #define PHY_ANY_ID "MATCH ANY PHY" 53 - #define PHY_ANY_UID 0xffffffff 54 - 55 52 struct phy_fixup { 56 53 struct list_head list; 57 54 char bus_id[MII_BUS_ID_SIZE + 3]; ··· 429 432 430 433 /** 431 434 * phy_register_fixup - creates a new phy_fixup and adds it to the list 432 - * @bus_id: A string which matches phydev->mdio.dev.bus_id (or PHY_ANY_ID) 435 + * @bus_id: A string which matches phydev->mdio.dev.bus_id (or NULL) 433 436 * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY) 434 - * It can also be PHY_ANY_UID 435 437 * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before 436 - * comparison 438 + * comparison (or 0 to disable id-based matching) 437 439 * @run: The actual code to be run when a matching PHY is found 438 440 */ 439 441 static int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask, ··· 443 447 if (!fixup) 444 448 return -ENOMEM; 445 449 446 - strscpy(fixup->bus_id, bus_id, sizeof(fixup->bus_id)); 450 + if (bus_id) 451 + strscpy(fixup->bus_id, bus_id, sizeof(fixup->bus_id)); 447 452 fixup->phy_uid = phy_uid; 448 453 fixup->phy_uid_mask = phy_uid_mask; 449 454 fixup->run = run; ··· 460 463 int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, 461 464 int (*run)(struct phy_device *)) 462 465 { 463 - return phy_register_fixup(PHY_ANY_ID, phy_uid, phy_uid_mask, run); 466 + return phy_register_fixup(NULL, phy_uid, phy_uid_mask, run); 464 467 } 465 468 EXPORT_SYMBOL(phy_register_fixup_for_uid); 466 469 ··· 468 471 int phy_register_fixup_for_id(const char *bus_id, 469 472 int (*run)(struct phy_device *)) 470 473 { 471 - return phy_register_fixup(bus_id, PHY_ANY_UID, 0xffffffff, run); 474 + return phy_register_fixup(bus_id, 0, 0, run); 472 475 } 473 476 EXPORT_SYMBOL(phy_register_fixup_for_id); 474 477 475 - /* Returns 1 if fixup matches phydev in bus_id and phy_uid. 476 - * Fixups can be set to match any in one or more fields. 477 - */ 478 - static int phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *fixup) 478 + static bool phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *fixup) 479 479 { 480 - if (strcmp(fixup->bus_id, phydev_name(phydev)) != 0) 481 - if (strcmp(fixup->bus_id, PHY_ANY_ID) != 0) 482 - return 0; 480 + if (!strcmp(fixup->bus_id, phydev_name(phydev))) 481 + return true; 483 482 484 - if (!phy_id_compare(phydev->phy_id, fixup->phy_uid, 485 - fixup->phy_uid_mask)) 486 - if (fixup->phy_uid != PHY_ANY_UID) 487 - return 0; 483 + if (fixup->phy_uid_mask && 484 + phy_id_compare(phydev->phy_id, fixup->phy_uid, fixup->phy_uid_mask)) 485 + return true; 488 486 489 - return 1; 487 + return false; 490 488 } 491 489 492 490 /* Runs any matching fixups for this phydev */