From 32d2a15ec54a3d8b708b343e50072ccb0e5da83f Mon Sep 17 00:00:00 2001 From: "Gustavo A. R. Silva" Date: Mon, 6 Mar 2023 14:59:04 -0600 Subject: [PATCH 1/6] platform/chrome: Replace fake flexible arrays with flexible-array member MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zero-length arrays as fake flexible arrays are deprecated and we are moving towards adopting C99 flexible-array members instead. Use the DECLARE_FLEX_ARRAY() helper macro to transform zero-length arrays in unions with flexible-array members. Address the following warning found with GCC-13 and -fstrict-flex-arrays=3 enabled: drivers/iio/accel/cros_ec_accel_legacy.c:66:46: warning: array subscript is outside array bounds of ‘struct ec_response_motion_sensor_data[0]’ [-Warray-bounds=] This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1]. Link: https://github.com/KSPP/linux/issues/21 Link: https://github.com/KSPP/linux/issues/193 Link: https://github.com/KSPP/linux/issues/262 Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] Signed-off-by: Gustavo A. R. Silva Signed-off-by: Tzung-Bi Shih Link: https://lore.kernel.org/r/ZAZUGBmSLc5wg7AK@work --- include/linux/platform_data/cros_ec_commands.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index 7e9c76aedd2d..ab721cf13a98 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -2701,7 +2701,7 @@ struct ec_response_motion_sense { * Sensor data is truncated if response_max is too small * for holding all the data. */ - struct ec_response_motion_sensor_data sensor[0]; + DECLARE_FLEX_ARRAY(struct ec_response_motion_sensor_data, sensor); } dump; /* Used for MOTIONSENSE_CMD_INFO. */ From 554ec02c97254962bbb0a8776c3160d294fc7e51 Mon Sep 17 00:00:00 2001 From: Tzung-Bi Shih Date: Wed, 8 Mar 2023 11:12:47 +0800 Subject: [PATCH 2/6] platform/chrome: cros_ec: remove unneeded label and if-condition Both `ec_dev->ec` and `ec_dev->pd` are initialized to NULL at the beginning of cros_ec_register(). Also, platform_device_unregister() takes care if the given platform_device is NULL. Remove the unneeded goto-label and if-condition. Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20230308031247.2866401-1-tzungbi@kernel.org --- drivers/platform/chrome/cros_ec.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c index b895c8130bba..8b7949220382 100644 --- a/drivers/platform/chrome/cros_ec.c +++ b/drivers/platform/chrome/cros_ec.c @@ -206,7 +206,7 @@ int cros_ec_register(struct cros_ec_device *ec_dev) err = cros_ec_query_all(ec_dev); if (err) { dev_err(dev, "Cannot identify the EC: error %d\n", err); - goto destroy_mutex; + goto exit; } if (ec_dev->irq > 0) { @@ -218,7 +218,7 @@ int cros_ec_register(struct cros_ec_device *ec_dev) if (err) { dev_err(dev, "Failed to request IRQ %d: %d\n", ec_dev->irq, err); - goto destroy_mutex; + goto exit; } } @@ -230,7 +230,7 @@ int cros_ec_register(struct cros_ec_device *ec_dev) dev_err(ec_dev->dev, "Failed to create CrOS EC platform device\n"); err = PTR_ERR(ec_dev->ec); - goto destroy_mutex; + goto exit; } if (ec_dev->max_passthru) { @@ -296,7 +296,6 @@ int cros_ec_register(struct cros_ec_device *ec_dev) exit: platform_device_unregister(ec_dev->ec); platform_device_unregister(ec_dev->pd); -destroy_mutex: mutex_destroy(&ec_dev->lock); lockdep_unregister_key(&ec_dev->lockdep_key); return err; @@ -313,8 +312,7 @@ EXPORT_SYMBOL(cros_ec_register); */ void cros_ec_unregister(struct cros_ec_device *ec_dev) { - if (ec_dev->pd) - platform_device_unregister(ec_dev->pd); + platform_device_unregister(ec_dev->pd); platform_device_unregister(ec_dev->ec); mutex_destroy(&ec_dev->lock); lockdep_unregister_key(&ec_dev->lockdep_key); From dc70234c408c644505a24362b0f095f713e4697e Mon Sep 17 00:00:00 2001 From: Liang He Date: Wed, 22 Mar 2023 12:16:57 +0800 Subject: [PATCH 3/6] platform/chrome: cros_typec_switch: Add missing fwnode_handle_put() In cros_typec_register_switches(), we should add fwnode_handle_put() when break out of the iteration device_for_each_child_node() as it will automatically increase and decrease the refcounter. Fixes: affc804c44c8 ("platform/chrome: cros_typec_switch: Add switch driver") Signed-off-by: Liang He Link: https://lore.kernel.org/r/20230322041657.1857001-1-windhl@126.com Signed-off-by: Prashant Malani --- drivers/platform/chrome/cros_typec_switch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/chrome/cros_typec_switch.c b/drivers/platform/chrome/cros_typec_switch.c index 9ed1605f4071..752720483753 100644 --- a/drivers/platform/chrome/cros_typec_switch.c +++ b/drivers/platform/chrome/cros_typec_switch.c @@ -270,6 +270,7 @@ static int cros_typec_register_switches(struct cros_typec_switch_data *sdata) return 0; err_switch: + fwnode_handle_put(fwnode); cros_typec_unregister_switches(sdata); return ret; } From 26e1dc1bef42a699734056271e790982e2ba8092 Mon Sep 17 00:00:00 2001 From: Rob Barnes Date: Mon, 10 Apr 2023 16:58:17 +0000 Subject: [PATCH 4/6] platform/chrome: cros_ec: Separate logic for getting panic info Create a separate function called cros_ec_get_panicinfo for getting panic info from EC. Currently cros_ec_create_panicinfo is the only caller. Signed-off-by: Rob Barnes Signed-off-by: Tzung-Bi Shih Link: https://lore.kernel.org/r/20230410165817.932449-1-robbarnes@google.com --- drivers/platform/chrome/cros_ec_debugfs.c | 42 ++++++++++++++++++----- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c index a98c529d8c69..414ebfffcf83 100644 --- a/drivers/platform/chrome/cros_ec_debugfs.c +++ b/drivers/platform/chrome/cros_ec_debugfs.c @@ -400,24 +400,48 @@ static void cros_ec_cleanup_console_log(struct cros_ec_debugfs *debug_info) } } -static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info) +/** + * Returns the size of the panicinfo data fetched from the EC + */ +static int cros_ec_get_panicinfo(struct cros_ec_device *ec_dev, uint8_t *data, + int data_size) { - struct cros_ec_device *ec_dev = debug_info->ec->ec_dev; int ret; struct cros_ec_command *msg; - int insize; - insize = ec_dev->max_response; + if (!data || data_size <= 0 || data_size > ec_dev->max_response) + return -EINVAL; - msg = devm_kzalloc(debug_info->ec->dev, - sizeof(*msg) + insize, GFP_KERNEL); + msg = kzalloc(sizeof(*msg) + data_size, GFP_KERNEL); if (!msg) return -ENOMEM; msg->command = EC_CMD_GET_PANIC_INFO; - msg->insize = insize; + msg->insize = data_size; ret = cros_ec_cmd_xfer_status(ec_dev, msg); + if (ret < 0) + goto free; + + memcpy(data, msg->data, data_size); + +free: + kfree(msg); + return ret; +} + +static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info) +{ + struct cros_ec_device *ec_dev = debug_info->ec->ec_dev; + int ret; + void *data; + + data = devm_kzalloc(debug_info->ec->dev, ec_dev->max_response, + GFP_KERNEL); + if (!data) + return -ENOMEM; + + ret = cros_ec_get_panicinfo(ec_dev, data, ec_dev->max_response); if (ret < 0) { ret = 0; goto free; @@ -427,7 +451,7 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info) if (ret == 0) goto free; - debug_info->panicinfo_blob.data = msg->data; + debug_info->panicinfo_blob.data = data; debug_info->panicinfo_blob.size = ret; debugfs_create_blob("panicinfo", S_IFREG | 0444, debug_info->dir, @@ -436,7 +460,7 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info) return 0; free: - devm_kfree(debug_info->ec->dev, msg); + devm_kfree(debug_info->ec->dev, data); return ret; } From 1f3744b89164a430865d18b757b86c4007627855 Mon Sep 17 00:00:00 2001 From: Tzung-Bi Shih Date: Tue, 11 Apr 2023 13:33:08 +0800 Subject: [PATCH 5/6] platform/chrome: cros_ec_debugfs: fix kernel-doc warning Fix the following kernel-doc warning: $ ./scripts/kernel-doc -none drivers/platform/chrome/* [...] warning: This comment starts with '/**', but isn't a kernel-doc comment. Fixes: 14bb09b32f43 ("platform/chrome: cros_ec: Separate logic for getting panic info") Reported-by: kernel test robot Signed-off-by: Tzung-Bi Shih Reviewed-by: Benson Leung Link: https://lore.kernel.org/r/20230411053308.1572493-1-tzungbi@kernel.org --- drivers/platform/chrome/cros_ec_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c index 414ebfffcf83..c876120e0ebc 100644 --- a/drivers/platform/chrome/cros_ec_debugfs.c +++ b/drivers/platform/chrome/cros_ec_debugfs.c @@ -400,7 +400,7 @@ static void cros_ec_cleanup_console_log(struct cros_ec_debugfs *debug_info) } } -/** +/* * Returns the size of the panicinfo data fetched from the EC */ static int cros_ec_get_panicinfo(struct cros_ec_device *ec_dev, uint8_t *data, From d184d60aa301e424cd0cf7de90b40744710a2417 Mon Sep 17 00:00:00 2001 From: Zhengkang Huang Date: Wed, 19 Apr 2023 18:03:03 +0800 Subject: [PATCH 6/6] platform/chrome: wilco_ec: remove return value check of debugfs_create_dir() Smatch complains that: wilco_ec_debugfs_probe() warn: 'debug_info->dir' is an error pointer or valid Debugfs checks are generally not supposed to be checked for errors and it is not necessary here. Just delete the dead code. Signed-off-by: Zhengkang Huang Reviewed-by: Dongliang Mu Signed-off-by: Tzung-Bi Shih Link: https://lore.kernel.org/r/20230419100303.343379-1-zkhuang@hust.edu.cn --- drivers/platform/chrome/wilco_ec/debugfs.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/platform/chrome/wilco_ec/debugfs.c b/drivers/platform/chrome/wilco_ec/debugfs.c index a812788a0bdc..7a13f13b16cd 100644 --- a/drivers/platform/chrome/wilco_ec/debugfs.c +++ b/drivers/platform/chrome/wilco_ec/debugfs.c @@ -251,8 +251,6 @@ static int wilco_ec_debugfs_probe(struct platform_device *pdev) return 0; debug_info->ec = ec; debug_info->dir = debugfs_create_dir("wilco_ec", NULL); - if (!debug_info->dir) - return 0; debugfs_create_file("raw", 0644, debug_info->dir, NULL, &fops_raw); debugfs_create_file("h1_gpio", 0444, debug_info->dir, ec, &fops_h1_gpio);