platform/chrome: Centralize cros_ec_device allocation
authorTzung-Bi Shih <tzungbi@kernel.org>
Thu, 28 Aug 2025 08:35:57 +0000 (08:35 +0000)
committerTzung-Bi Shih <tzungbi@kernel.org>
Sun, 14 Sep 2025 03:34:41 +0000 (11:34 +0800)
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>
drivers/platform/chrome/cros_ec.c
drivers/platform/chrome/cros_ec.h
drivers/platform/chrome/cros_ec_i2c.c
drivers/platform/chrome/cros_ec_ishtp.c
drivers/platform/chrome/cros_ec_lpc.c
drivers/platform/chrome/cros_ec_rpmsg.c
drivers/platform/chrome/cros_ec_spi.c
drivers/platform/chrome/cros_ec_uart.c

index b173036..25283a1 100644 (file)
@@ -30,6 +30,18 @@ static struct cros_ec_platform pd_p = {
        .cmd_offset = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX),
 };
 
+struct cros_ec_device *cros_ec_device_alloc(struct device *dev)
+{
+       struct cros_ec_device *ec_dev;
+
+       ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
+       if (!ec_dev)
+               return NULL;
+
+       return ec_dev;
+}
+EXPORT_SYMBOL(cros_ec_device_alloc);
+
 /**
  * cros_ec_irq_handler() - top half part of the interrupt handler
  * @irq: IRQ id
index 6b95f1e..cd4643b 100644 (file)
@@ -11,6 +11,9 @@
 #include <linux/interrupt.h>
 
 struct cros_ec_device;
+struct device;
+
+struct cros_ec_device *cros_ec_device_alloc(struct device *dev);
 
 int cros_ec_register(struct cros_ec_device *ec_dev);
 void cros_ec_unregister(struct cros_ec_device *ec_dev);
index 38af97c..ee3c513 100644 (file)
@@ -289,10 +289,10 @@ done:
 static int cros_ec_i2c_probe(struct i2c_client *client)
 {
        struct device *dev = &client->dev;
-       struct cros_ec_device *ec_dev = NULL;
+       struct cros_ec_device *ec_dev;
        int err;
 
-       ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
+       ec_dev = cros_ec_device_alloc(dev);
        if (!ec_dev)
                return -ENOMEM;
 
index 7e7190b..c102a79 100644 (file)
@@ -543,7 +543,7 @@ static int cros_ec_dev_init(struct ishtp_cl_data *client_data)
        struct cros_ec_device *ec_dev;
        struct device *dev = cl_data_to_dev(client_data);
 
-       ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
+       ec_dev = cros_ec_device_alloc(dev);
        if (!ec_dev)
                return -ENOMEM;
 
index 7d9a782..30fa89b 100644 (file)
@@ -637,7 +637,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
                }
        }
 
-       ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
+       ec_dev = cros_ec_device_alloc(dev);
        if (!ec_dev)
                return -ENOMEM;
 
index bc26664..9ac2b92 100644 (file)
@@ -216,7 +216,7 @@ static int cros_ec_rpmsg_probe(struct rpmsg_device *rpdev)
        struct cros_ec_device *ec_dev;
        int ret;
 
-       ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
+       ec_dev = cros_ec_device_alloc(dev);
        if (!ec_dev)
                return -ENOMEM;
 
index 8ca0f85..c778300 100644 (file)
@@ -749,7 +749,7 @@ static int cros_ec_spi_probe(struct spi_device *spi)
        if (ec_spi == NULL)
                return -ENOMEM;
        ec_spi->spi = spi;
-       ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
+       ec_dev = cros_ec_device_alloc(dev);
        if (!ec_dev)
                return -ENOMEM;
 
index 19c179d..1a7511b 100644 (file)
@@ -259,7 +259,7 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
        if (!ec_uart)
                return -ENOMEM;
 
-       ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
+       ec_dev = cros_ec_device_alloc(dev);
        if (!ec_dev)
                return -ENOMEM;