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.

platform/chrome: Centralize cros_ec_device allocation

Introduce a helper function, cros_ec_device_alloc(), to centralize the
allocation of the struct cros_ec_device. Convert all protocol device
drivers to use this new function.

This is a preparatory step for separating common initialization logic
out of device drivers' probe() and cros_ec_register().

Link: https://lore.kernel.org/r/20250828083601.856083-2-tzungbi@kernel.org
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

+22 -7
+12
drivers/platform/chrome/cros_ec.c
··· 30 30 .cmd_offset = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX), 31 31 }; 32 32 33 + struct cros_ec_device *cros_ec_device_alloc(struct device *dev) 34 + { 35 + struct cros_ec_device *ec_dev; 36 + 37 + ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); 38 + if (!ec_dev) 39 + return NULL; 40 + 41 + return ec_dev; 42 + } 43 + EXPORT_SYMBOL(cros_ec_device_alloc); 44 + 33 45 /** 34 46 * cros_ec_irq_handler() - top half part of the interrupt handler 35 47 * @irq: IRQ id
+3
drivers/platform/chrome/cros_ec.h
··· 11 11 #include <linux/interrupt.h> 12 12 13 13 struct cros_ec_device; 14 + struct device; 15 + 16 + struct cros_ec_device *cros_ec_device_alloc(struct device *dev); 14 17 15 18 int cros_ec_register(struct cros_ec_device *ec_dev); 16 19 void cros_ec_unregister(struct cros_ec_device *ec_dev);
+2 -2
drivers/platform/chrome/cros_ec_i2c.c
··· 289 289 static int cros_ec_i2c_probe(struct i2c_client *client) 290 290 { 291 291 struct device *dev = &client->dev; 292 - struct cros_ec_device *ec_dev = NULL; 292 + struct cros_ec_device *ec_dev; 293 293 int err; 294 294 295 - ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); 295 + ec_dev = cros_ec_device_alloc(dev); 296 296 if (!ec_dev) 297 297 return -ENOMEM; 298 298
+1 -1
drivers/platform/chrome/cros_ec_ishtp.c
··· 543 543 struct cros_ec_device *ec_dev; 544 544 struct device *dev = cl_data_to_dev(client_data); 545 545 546 - ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); 546 + ec_dev = cros_ec_device_alloc(dev); 547 547 if (!ec_dev) 548 548 return -ENOMEM; 549 549
+1 -1
drivers/platform/chrome/cros_ec_lpc.c
··· 637 637 } 638 638 } 639 639 640 - ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); 640 + ec_dev = cros_ec_device_alloc(dev); 641 641 if (!ec_dev) 642 642 return -ENOMEM; 643 643
+1 -1
drivers/platform/chrome/cros_ec_rpmsg.c
··· 216 216 struct cros_ec_device *ec_dev; 217 217 int ret; 218 218 219 - ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); 219 + ec_dev = cros_ec_device_alloc(dev); 220 220 if (!ec_dev) 221 221 return -ENOMEM; 222 222
+1 -1
drivers/platform/chrome/cros_ec_spi.c
··· 749 749 if (ec_spi == NULL) 750 750 return -ENOMEM; 751 751 ec_spi->spi = spi; 752 - ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); 752 + ec_dev = cros_ec_device_alloc(dev); 753 753 if (!ec_dev) 754 754 return -ENOMEM; 755 755
+1 -1
drivers/platform/chrome/cros_ec_uart.c
··· 259 259 if (!ec_uart) 260 260 return -ENOMEM; 261 261 262 - ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL); 262 + ec_dev = cros_ec_device_alloc(dev); 263 263 if (!ec_dev) 264 264 return -ENOMEM; 265 265