From 773997c92d9680da272730e5028caa93d361fcfc Mon Sep 17 00:00:00 2001 From: Maximilian Brune Date: Fri, 7 Nov 2025 18:43:28 +0100 Subject: [PATCH] drivers/intel/touch: Avoid returning undefined pointer Currently we may return an undefined pointer called `none_driver_config` since stack variables are not by default initialized to 0/NULL. This also causes an issue when updating to a clang version 21.1.5 from version 18.1.8, since it complains about this very issue. returning NULL is fine, since the macros in this file actually depend on it to figure out where to get the config from. Signed-off-by: Maximilian Brune Change-Id: I7b719ca9fd41409375f635b1dcddbc5796b48fe7 Reviewed-on: https://review.coreboot.org/c/coreboot/+/89940 Tested-by: build bot (Jenkins) Reviewed-by: Angel Pons --- src/drivers/intel/touch/chip.h | 1 - src/drivers/intel/touch/touch.c | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/drivers/intel/touch/chip.h b/src/drivers/intel/touch/chip.h index 9f3ad3f525..69b58f83aa 100644 --- a/src/drivers/intel/touch/chip.h +++ b/src/drivers/intel/touch/chip.h @@ -178,7 +178,6 @@ enum intel_touch_device { TH_SENSOR_GOOGLE, /* ELAN9006 for SPI and ELAN6918 for I2C */ TH_SENSOR_HYNITRON, /* NYITRON for I2C only */ TH_SENSOR_GENERIC, /* for device properity thru devicetree */ - TH_SENSOR_MAX }; /* diff --git a/src/drivers/intel/touch/touch.c b/src/drivers/intel/touch/touch.c index b070c47d7f..5bca4173c6 100644 --- a/src/drivers/intel/touch/touch.c +++ b/src/drivers/intel/touch/touch.c @@ -39,17 +39,17 @@ __weak const struct intel_thc_hidspi_info *soc_get_thc_hidspi_info(void) { retur static const struct drivers_intel_touch_config *get_driver_config(const struct device *dev) { - const struct drivers_intel_touch_config none_driver_config; const struct drivers_intel_touch_config *config = dev->chip_info; - const struct drivers_intel_touch_config *devices[TH_SENSOR_MAX] = { - [TH_SENSOR_NONE] = &none_driver_config, - [TH_SENSOR_WACOM] = &wacom_touch_config, - [TH_SENSOR_ELAN] = &elan_touch_config, - [TH_SENSOR_GOOGLE] = &google_touch_config, - [TH_SENSOR_HYNITRON] = &hynitron_touch_config, - [TH_SENSOR_GENERIC] = config - }; - return devices[config->connected_device]; + switch (config->connected_device) { + case TH_SENSOR_WACOM: return &wacom_touch_config; + case TH_SENSOR_ELAN: return &elan_touch_config; + case TH_SENSOR_GOOGLE: return &google_touch_config; + case TH_SENSOR_HYNITRON: return &hynitron_touch_config; + case TH_SENSOR_GENERIC: return config; + case TH_SENSOR_NONE: return NULL; + /* no default so that we get an error in case someone forgets to add a case here */ + } + return NULL; } /* Use only Device-tree definition. */