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: dsa: mt7530: Constify struct regmap_config

'struct regmap_config' are not modified in these drivers. They be
statically defined instead of allocated and populated at run-time.

The main benefits are:
- it saves some memory at runtime
- the structures can be declared as 'const', which is always better for
structures that hold some function pointers
- the code is less verbose

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Christophe JAILLET and committed by
David S. Miller
9eb73f92 8c2e6022

+19 -23
+9 -12
drivers/net/dsa/mt7530-mdio.c
··· 136 136 }; 137 137 MODULE_DEVICE_TABLE(of, mt7530_of_match); 138 138 139 + static const struct regmap_config regmap_config = { 140 + .reg_bits = 16, 141 + .val_bits = 32, 142 + .reg_stride = 4, 143 + .max_register = MT7530_CREV, 144 + .disable_locking = true, 145 + }; 146 + 139 147 static int 140 148 mt7530_probe(struct mdio_device *mdiodev) 141 149 { 142 - static struct regmap_config *regmap_config; 143 150 struct mt7530_priv *priv; 144 151 struct device_node *dn; 145 152 int ret; ··· 200 193 return PTR_ERR(priv->io_pwr); 201 194 } 202 195 203 - regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config), 204 - GFP_KERNEL); 205 - if (!regmap_config) 206 - return -ENOMEM; 207 - 208 - regmap_config->reg_bits = 16; 209 - regmap_config->val_bits = 32; 210 - regmap_config->reg_stride = 4; 211 - regmap_config->max_register = MT7530_CREV; 212 - regmap_config->disable_locking = true; 213 196 priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus, priv, 214 - regmap_config); 197 + &regmap_config); 215 198 if (IS_ERR(priv->regmap)) 216 199 return PTR_ERR(priv->regmap); 217 200
+10 -11
drivers/net/dsa/mt7530-mmio.c
··· 18 18 }; 19 19 MODULE_DEVICE_TABLE(of, mt7988_of_match); 20 20 21 + static const struct regmap_config sw_regmap_config = { 22 + .name = "switch", 23 + .reg_bits = 16, 24 + .val_bits = 32, 25 + .reg_stride = 4, 26 + .max_register = MT7530_CREV, 27 + }; 28 + 21 29 static int 22 30 mt7988_probe(struct platform_device *pdev) 23 31 { 24 - static struct regmap_config *sw_regmap_config; 25 32 struct mt7530_priv *priv; 26 33 void __iomem *base_addr; 27 34 int ret; ··· 56 49 return -ENXIO; 57 50 } 58 51 59 - sw_regmap_config = devm_kzalloc(&pdev->dev, sizeof(*sw_regmap_config), GFP_KERNEL); 60 - if (!sw_regmap_config) 61 - return -ENOMEM; 62 - 63 - sw_regmap_config->name = "switch"; 64 - sw_regmap_config->reg_bits = 16; 65 - sw_regmap_config->val_bits = 32; 66 - sw_regmap_config->reg_stride = 4; 67 - sw_regmap_config->max_register = MT7530_CREV; 68 - priv->regmap = devm_regmap_init_mmio(&pdev->dev, base_addr, sw_regmap_config); 52 + priv->regmap = devm_regmap_init_mmio(&pdev->dev, base_addr, 53 + &sw_regmap_config); 69 54 if (IS_ERR(priv->regmap)) 70 55 return PTR_ERR(priv->regmap); 71 56