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 common cros_ec_device initialization

Move the common initialization from protocol device drivers into central
cros_ec_device_alloc().

This removes duplicated code from each driver's probe function.
The buffer sizes are now calculated once, using the maximum possible
overhead required by any of the transport protocols, ensuring the
allocated buffers are sufficient for all cases.

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

+19 -30
+9
drivers/platform/chrome/cros_ec.c
··· 38 38 if (!ec_dev) 39 39 return NULL; 40 40 41 + ec_dev->din_size = sizeof(struct ec_host_response) + 42 + sizeof(struct ec_response_get_protocol_info) + 43 + EC_MAX_RESPONSE_OVERHEAD; 44 + ec_dev->dout_size = sizeof(struct ec_host_request) + 45 + sizeof(struct ec_params_rwsig_action) + 46 + EC_MAX_REQUEST_OVERHEAD; 47 + 48 + ec_dev->dev = dev; 49 + 41 50 return ec_dev; 42 51 } 43 52 EXPORT_SYMBOL(cros_ec_device_alloc);
-5
drivers/platform/chrome/cros_ec_i2c.c
··· 297 297 return -ENOMEM; 298 298 299 299 i2c_set_clientdata(client, ec_dev); 300 - ec_dev->dev = dev; 301 300 ec_dev->priv = client; 302 301 ec_dev->irq = client->irq; 303 302 ec_dev->cmd_xfer = cros_ec_cmd_xfer_i2c; 304 303 ec_dev->pkt_xfer = cros_ec_pkt_xfer_i2c; 305 304 ec_dev->phys_name = client->adapter->name; 306 - ec_dev->din_size = sizeof(struct ec_host_response_i2c) + 307 - sizeof(struct ec_response_get_protocol_info); 308 - ec_dev->dout_size = sizeof(struct ec_host_request_i2c) + 309 - sizeof(struct ec_params_rwsig_action); 310 305 311 306 err = cros_ec_register(ec_dev); 312 307 if (err) {
-4
drivers/platform/chrome/cros_ec_ishtp.c
··· 550 550 client_data->ec_dev = ec_dev; 551 551 dev->driver_data = ec_dev; 552 552 553 - ec_dev->dev = dev; 554 553 ec_dev->priv = client_data->cros_ish_cl; 555 554 ec_dev->cmd_xfer = NULL; 556 555 ec_dev->pkt_xfer = cros_ec_pkt_xfer_ish; 557 556 ec_dev->phys_name = dev_name(dev); 558 - ec_dev->din_size = sizeof(struct cros_ish_in_msg) + 559 - sizeof(struct ec_response_get_protocol_info); 560 - ec_dev->dout_size = sizeof(struct cros_ish_out_msg) + sizeof(struct ec_params_rwsig_action); 561 557 562 558 return cros_ec_register(ec_dev); 563 559 }
-4
drivers/platform/chrome/cros_ec_lpc.c
··· 642 642 return -ENOMEM; 643 643 644 644 platform_set_drvdata(pdev, ec_dev); 645 - ec_dev->dev = dev; 646 645 ec_dev->phys_name = dev_name(dev); 647 646 ec_dev->cmd_xfer = cros_ec_cmd_xfer_lpc; 648 647 ec_dev->pkt_xfer = cros_ec_pkt_xfer_lpc; 649 648 ec_dev->cmd_readmem = cros_ec_lpc_readmem; 650 - ec_dev->din_size = sizeof(struct ec_host_response) + 651 - sizeof(struct ec_response_get_protocol_info); 652 - ec_dev->dout_size = sizeof(struct ec_host_request) + sizeof(struct ec_params_rwsig_action); 653 649 ec_dev->priv = ec_lpc; 654 650 655 651 /*
-4
drivers/platform/chrome/cros_ec_rpmsg.c
··· 224 224 if (!ec_rpmsg) 225 225 return -ENOMEM; 226 226 227 - ec_dev->dev = dev; 228 227 ec_dev->priv = ec_rpmsg; 229 228 ec_dev->cmd_xfer = cros_ec_cmd_xfer_rpmsg; 230 229 ec_dev->pkt_xfer = cros_ec_pkt_xfer_rpmsg; 231 230 ec_dev->phys_name = dev_name(&rpdev->dev); 232 - ec_dev->din_size = sizeof(struct ec_host_response) + 233 - sizeof(struct ec_response_get_protocol_info); 234 - ec_dev->dout_size = sizeof(struct ec_host_request) + sizeof(struct ec_params_rwsig_action); 235 231 dev_set_drvdata(dev, ec_dev); 236 232 237 233 ec_rpmsg->rpdev = rpdev;
-5
drivers/platform/chrome/cros_ec_spi.c
··· 757 757 cros_ec_spi_dt_probe(ec_spi, dev); 758 758 759 759 spi_set_drvdata(spi, ec_dev); 760 - ec_dev->dev = dev; 761 760 ec_dev->priv = ec_spi; 762 761 ec_dev->irq = spi->irq; 763 762 ec_dev->cmd_xfer = cros_ec_cmd_xfer_spi; 764 763 ec_dev->pkt_xfer = cros_ec_pkt_xfer_spi; 765 764 ec_dev->phys_name = dev_name(&ec_spi->spi->dev); 766 - ec_dev->din_size = EC_MSG_PREAMBLE_COUNT + 767 - sizeof(struct ec_host_response) + 768 - sizeof(struct ec_response_get_protocol_info); 769 - ec_dev->dout_size = sizeof(struct ec_host_request) + sizeof(struct ec_params_rwsig_action); 770 765 771 766 ec_spi->last_transfer_ns = ktime_get_ns(); 772 767
-4
drivers/platform/chrome/cros_ec_uart.c
··· 276 276 277 277 /* Initialize ec_dev for cros_ec */ 278 278 ec_dev->phys_name = dev_name(dev); 279 - ec_dev->dev = dev; 280 279 ec_dev->priv = ec_uart; 281 280 ec_dev->irq = ec_uart->irq; 282 281 ec_dev->cmd_xfer = NULL; 283 282 ec_dev->pkt_xfer = cros_ec_uart_pkt_xfer; 284 - ec_dev->din_size = sizeof(struct ec_host_response) + 285 - sizeof(struct ec_response_get_protocol_info); 286 - ec_dev->dout_size = sizeof(struct ec_host_request) + sizeof(struct ec_params_rwsig_action); 287 283 288 284 serdev_device_set_client_ops(serdev, &cros_ec_uart_client_ops); 289 285
+10 -4
include/linux/platform_data/cros_ec_proto.h
··· 33 33 34 34 /* 35 35 * Max bus-specific overhead incurred by request/responses. 36 - * I2C requires 1 additional byte for requests. 37 - * I2C requires 2 additional bytes for responses. 38 - * SPI requires up to 32 additional bytes for responses. 36 + * 37 + * Request: 38 + * - I2C requires 1 byte (see struct ec_host_request_i2c). 39 + * - ISHTP requires 4 bytes (see struct cros_ish_out_msg). 40 + * 41 + * Response: 42 + * - I2C requires 2 bytes (see struct ec_host_response_i2c). 43 + * - ISHTP requires 4 bytes (see struct cros_ish_in_msg). 44 + * - SPI requires 32 bytes (see EC_MSG_PREAMBLE_COUNT). 39 45 */ 40 46 #define EC_PROTO_VERSION_UNKNOWN 0 41 - #define EC_MAX_REQUEST_OVERHEAD 1 47 + #define EC_MAX_REQUEST_OVERHEAD 4 42 48 #define EC_MAX_RESPONSE_OVERHEAD 32 43 49 44 50 /*