Skip to content

Commit 9188569

Browse files
author
Tzung-Bi Shih
committed
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>
1 parent f7439a7 commit 9188569

8 files changed

Lines changed: 22 additions & 7 deletions

File tree

drivers/platform/chrome/cros_ec.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ static struct cros_ec_platform pd_p = {
3030
.cmd_offset = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX),
3131
};
3232

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+
3345
/**
3446
* cros_ec_irq_handler() - top half part of the interrupt handler
3547
* @irq: IRQ id

drivers/platform/chrome/cros_ec.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <linux/interrupt.h>
1212

1313
struct cros_ec_device;
14+
struct device;
15+
16+
struct cros_ec_device *cros_ec_device_alloc(struct device *dev);
1417

1518
int cros_ec_register(struct cros_ec_device *ec_dev);
1619
void cros_ec_unregister(struct cros_ec_device *ec_dev);

drivers/platform/chrome/cros_ec_i2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ static int cros_ec_cmd_xfer_i2c(struct cros_ec_device *ec_dev,
289289
static int cros_ec_i2c_probe(struct i2c_client *client)
290290
{
291291
struct device *dev = &client->dev;
292-
struct cros_ec_device *ec_dev = NULL;
292+
struct cros_ec_device *ec_dev;
293293
int err;
294294

295-
ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
295+
ec_dev = cros_ec_device_alloc(dev);
296296
if (!ec_dev)
297297
return -ENOMEM;
298298

drivers/platform/chrome/cros_ec_ishtp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ static int cros_ec_dev_init(struct ishtp_cl_data *client_data)
543543
struct cros_ec_device *ec_dev;
544544
struct device *dev = cl_data_to_dev(client_data);
545545

546-
ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
546+
ec_dev = cros_ec_device_alloc(dev);
547547
if (!ec_dev)
548548
return -ENOMEM;
549549

drivers/platform/chrome/cros_ec_lpc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
637637
}
638638
}
639639

640-
ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
640+
ec_dev = cros_ec_device_alloc(dev);
641641
if (!ec_dev)
642642
return -ENOMEM;
643643

drivers/platform/chrome/cros_ec_rpmsg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int cros_ec_rpmsg_probe(struct rpmsg_device *rpdev)
216216
struct cros_ec_device *ec_dev;
217217
int ret;
218218

219-
ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
219+
ec_dev = cros_ec_device_alloc(dev);
220220
if (!ec_dev)
221221
return -ENOMEM;
222222

drivers/platform/chrome/cros_ec_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ static int cros_ec_spi_probe(struct spi_device *spi)
749749
if (ec_spi == NULL)
750750
return -ENOMEM;
751751
ec_spi->spi = spi;
752-
ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
752+
ec_dev = cros_ec_device_alloc(dev);
753753
if (!ec_dev)
754754
return -ENOMEM;
755755

drivers/platform/chrome/cros_ec_uart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static int cros_ec_uart_probe(struct serdev_device *serdev)
259259
if (!ec_uart)
260260
return -ENOMEM;
261261

262-
ec_dev = devm_kzalloc(dev, sizeof(*ec_dev), GFP_KERNEL);
262+
ec_dev = cros_ec_device_alloc(dev);
263263
if (!ec_dev)
264264
return -ENOMEM;
265265

0 commit comments

Comments
 (0)