diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/net/phy | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/net/phy')
| -rw-r--r-- | drivers/net/phy/as21xxx.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/dp83640.c | 9 | ||||
| -rw-r--r-- | drivers/net/phy/mdio_device.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/micrel.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/microchip_rds_ptp.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/mii_timestamper.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/mscc/mscc_macsec.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/nxp-c45-tja11xx-macsec.c | 4 | ||||
| -rw-r--r-- | drivers/net/phy/phy.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/phy_device.c | 4 | ||||
| -rw-r--r-- | drivers/net/phy/phy_led_triggers.c | 9 | ||||
| -rw-r--r-- | drivers/net/phy/phy_link_topology.c | 4 | ||||
| -rw-r--r-- | drivers/net/phy/phy_package.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/phy_port.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/phylink.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/sfp-bus.c | 2 | ||||
| -rw-r--r-- | drivers/net/phy/sfp.c | 2 |
17 files changed, 26 insertions, 28 deletions
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c index 005277360656..d3954ea6b1dd 100644 --- a/drivers/net/phy/as21xxx.c +++ b/drivers/net/phy/as21xxx.c @@ -907,7 +907,7 @@ static int as21xxx_match_phy_device(struct phy_device *phydev, return phy_id == phydrv->phy_id; /* Allocate temp priv and load the firmware */ - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = kzalloc_obj(*priv, GFP_KERNEL); if (!priv) return -ENOMEM; diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c index b950acc9c49b..a56f4302840f 100644 --- a/drivers/net/phy/dp83640.c +++ b/drivers/net/phy/dp83640.c @@ -1027,13 +1027,12 @@ static struct dp83640_clock *dp83640_clock_get_bus(struct mii_bus *bus) if (clock) goto out; - clock = kzalloc(sizeof(struct dp83640_clock), GFP_KERNEL); + clock = kzalloc_obj(struct dp83640_clock, GFP_KERNEL); if (!clock) goto out; - clock->caps.pin_config = kcalloc(DP83640_N_PINS, - sizeof(struct ptp_pin_desc), - GFP_KERNEL); + clock->caps.pin_config = kzalloc_objs(struct ptp_pin_desc, + DP83640_N_PINS, GFP_KERNEL); if (!clock->caps.pin_config) { kfree(clock); clock = NULL; @@ -1412,7 +1411,7 @@ static int dp83640_probe(struct phy_device *phydev) if (!clock) goto no_clock; - dp83640 = kzalloc(sizeof(struct dp83640_private), GFP_KERNEL); + dp83640 = kzalloc_obj(struct dp83640_private, GFP_KERNEL); if (!dp83640) goto no_memory; diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c index 65636070a222..172fbfcb215c 100644 --- a/drivers/net/phy/mdio_device.c +++ b/drivers/net/phy/mdio_device.c @@ -41,7 +41,7 @@ struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr) struct mdio_device *mdiodev; /* We allocate the device, and initialize the default values */ - mdiodev = kzalloc(sizeof(*mdiodev), GFP_KERNEL); + mdiodev = kzalloc_obj(*mdiodev, GFP_KERNEL); if (!mdiodev) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 663dcdc92204..5ef9248c6b49 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -4114,7 +4114,7 @@ static void lan8814_get_rx_ts(struct kszphy_ptp_priv *ptp_priv) u32 reg; do { - rx_ts = kzalloc(sizeof(*rx_ts), GFP_KERNEL); + rx_ts = kzalloc_obj(*rx_ts, GFP_KERNEL); if (!rx_ts) return; diff --git a/drivers/net/phy/microchip_rds_ptp.c b/drivers/net/phy/microchip_rds_ptp.c index f5f2928e705f..9307df6f6d11 100644 --- a/drivers/net/phy/microchip_rds_ptp.c +++ b/drivers/net/phy/microchip_rds_ptp.c @@ -999,7 +999,7 @@ static struct mchp_rds_ptp_rx_ts if (rc < 0) goto error; - rx_ts = kmalloc(sizeof(*rx_ts), GFP_KERNEL); + rx_ts = kmalloc_obj(*rx_ts, GFP_KERNEL); if (!rx_ts) return NULL; diff --git a/drivers/net/phy/mii_timestamper.c b/drivers/net/phy/mii_timestamper.c index 51ae0593a04f..259ed30897c7 100644 --- a/drivers/net/phy/mii_timestamper.c +++ b/drivers/net/phy/mii_timestamper.c @@ -28,7 +28,7 @@ int register_mii_tstamp_controller(struct device *device, { struct mii_timestamping_desc *desc; - desc = kzalloc(sizeof(*desc), GFP_KERNEL); + desc = kzalloc_obj(*desc, GFP_KERNEL); if (!desc) return -ENOMEM; diff --git a/drivers/net/phy/mscc/mscc_macsec.c b/drivers/net/phy/mscc/mscc_macsec.c index 9a38a29cf397..ed0d445ce1e1 100644 --- a/drivers/net/phy/mscc/mscc_macsec.c +++ b/drivers/net/phy/mscc/mscc_macsec.c @@ -610,7 +610,7 @@ static struct macsec_flow *vsc8584_macsec_alloc_flow(struct vsc8531_private *pri if (index == MSCC_MS_MAX_FLOWS) return ERR_PTR(-ENOMEM); - flow = kzalloc(sizeof(*flow), GFP_KERNEL); + flow = kzalloc_obj(*flow, GFP_KERNEL); if (!flow) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/phy/nxp-c45-tja11xx-macsec.c b/drivers/net/phy/nxp-c45-tja11xx-macsec.c index fc897ba79b03..21519a2d9f85 100644 --- a/drivers/net/phy/nxp-c45-tja11xx-macsec.c +++ b/drivers/net/phy/nxp-c45-tja11xx-macsec.c @@ -431,7 +431,7 @@ static struct nxp_c45_sa *nxp_c45_sa_alloc(struct list_head *sa_list, void *sa, return ERR_PTR(-ENOSPC); } - tmp = kzalloc(sizeof(*tmp), GFP_KERNEL); + tmp = kzalloc_obj(*tmp, GFP_KERNEL); if (!tmp) return ERR_PTR(-ENOMEM); @@ -991,7 +991,7 @@ static int nxp_c45_mdo_add_secy(struct macsec_context *ctx) if (idx == TX_SC_MAX) return -ENOSPC; - phy_secy = kzalloc(sizeof(*phy_secy), GFP_KERNEL); + phy_secy = kzalloc_obj(*phy_secy, GFP_KERNEL); if (!phy_secy) return -ENOMEM; diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 13dd1691886d..376bfa923349 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -736,7 +736,7 @@ int phy_ethtool_set_plca_cfg(struct phy_device *phydev, goto out; } - curr_plca_cfg = kmalloc(sizeof(*curr_plca_cfg), GFP_KERNEL); + curr_plca_cfg = kmalloc_obj(*curr_plca_cfg, GFP_KERNEL); if (!curr_plca_cfg) { ret = -ENOMEM; goto out; diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 9b8eaac63b90..52c2ff7fc6ae 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -438,7 +438,7 @@ static SIMPLE_DEV_PM_OPS(mdio_bus_phy_pm_ops, mdio_bus_phy_suspend, static int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask, int (*run)(struct phy_device *)) { - struct phy_fixup *fixup = kzalloc(sizeof(*fixup), GFP_KERNEL); + struct phy_fixup *fixup = kzalloc_obj(*fixup, GFP_KERNEL); if (!fixup) return -ENOMEM; @@ -754,7 +754,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, int ret = 0; /* We allocate the device, and initialize the default values */ - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/phy/phy_led_triggers.c b/drivers/net/phy/phy_led_triggers.c index 60893691d4c3..7821fe19934c 100644 --- a/drivers/net/phy/phy_led_triggers.c +++ b/drivers/net/phy/phy_led_triggers.c @@ -93,8 +93,7 @@ int phy_led_triggers_register(struct phy_device *phy) if (!phy->phy_num_led_triggers) return 0; - phy->led_link_trigger = kzalloc(sizeof(*phy->led_link_trigger), - GFP_KERNEL); + phy->led_link_trigger = kzalloc_obj(*phy->led_link_trigger, GFP_KERNEL); if (!phy->led_link_trigger) { err = -ENOMEM; goto out_clear; @@ -104,9 +103,9 @@ int phy_led_triggers_register(struct phy_device *phy) if (err) goto out_free_link; - phy->phy_led_triggers = kcalloc(phy->phy_num_led_triggers, - sizeof(struct phy_led_trigger), - GFP_KERNEL); + phy->phy_led_triggers = kzalloc_objs(struct phy_led_trigger, + phy->phy_num_led_triggers, + GFP_KERNEL); if (!phy->phy_led_triggers) { err = -ENOMEM; goto out_unreg_link; diff --git a/drivers/net/phy/phy_link_topology.c b/drivers/net/phy/phy_link_topology.c index 0e9e987f37dd..ed15599dd38d 100644 --- a/drivers/net/phy/phy_link_topology.c +++ b/drivers/net/phy/phy_link_topology.c @@ -15,7 +15,7 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev) { struct phy_link_topology *topo; - topo = kzalloc(sizeof(*topo), GFP_KERNEL); + topo = kzalloc_obj(*topo, GFP_KERNEL); if (!topo) return -ENOMEM; @@ -43,7 +43,7 @@ int phy_link_topo_add_phy(struct net_device *dev, topo = dev->link_topo; } - pdn = kzalloc(sizeof(*pdn), GFP_KERNEL); + pdn = kzalloc_obj(*pdn, GFP_KERNEL); if (!pdn) return -ENOMEM; diff --git a/drivers/net/phy/phy_package.c b/drivers/net/phy/phy_package.c index 3024da0bbf7b..3137a8fecf21 100644 --- a/drivers/net/phy/phy_package.c +++ b/drivers/net/phy/phy_package.c @@ -219,7 +219,7 @@ int phy_package_join(struct phy_device *phydev, int base_addr, size_t priv_size) shared = bus->shared[base_addr]; if (!shared) { ret = -ENOMEM; - shared = kzalloc(sizeof(*shared), GFP_KERNEL); + shared = kzalloc_obj(*shared, GFP_KERNEL); if (!shared) goto err_unlock; if (priv_size) { diff --git a/drivers/net/phy/phy_port.c b/drivers/net/phy/phy_port.c index 63d1bb154dc7..cae133a25fb0 100644 --- a/drivers/net/phy/phy_port.c +++ b/drivers/net/phy/phy_port.c @@ -19,7 +19,7 @@ struct phy_port *phy_port_alloc(void) { struct phy_port *port; - port = kzalloc(sizeof(*port), GFP_KERNEL); + port = kzalloc_obj(*port, GFP_KERNEL); if (!port) return NULL; diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index e1f01d7fc4da..f21a69e34d1c 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1853,7 +1853,7 @@ struct phylink *phylink_create(struct phylink_config *config, return ERR_PTR(-EINVAL); } - pl = kzalloc(sizeof(*pl), GFP_KERNEL); + pl = kzalloc_obj(*pl, GFP_KERNEL); if (!pl) return ERR_PTR(-ENOMEM); diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c index b945d75966d5..07175bf3ef60 100644 --- a/drivers/net/phy/sfp-bus.c +++ b/drivers/net/phy/sfp-bus.c @@ -388,7 +388,7 @@ static struct sfp_bus *sfp_bus_get(const struct fwnode_handle *fwnode) { struct sfp_bus *sfp, *new, *found = NULL; - new = kzalloc(sizeof(*new), GFP_KERNEL); + new = kzalloc_obj(*new, GFP_KERNEL); mutex_lock(&sfp_mutex); diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 43aefdd8b70f..42a9c93f03b3 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -3029,7 +3029,7 @@ static struct sfp *sfp_alloc(struct device *dev) { struct sfp *sfp; - sfp = kzalloc(sizeof(*sfp), GFP_KERNEL); + sfp = kzalloc_obj(*sfp, GFP_KERNEL); if (!sfp) return ERR_PTR(-ENOMEM); |
