mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: temperature: ltc2983: avoid -Wstring-compare warning
@ 2026-10-02 12:48 Arnd Bergmann
  2026-10-02 13:04 ` Joshua Crofts
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2026-10-02 12:48 UTC (permalink / raw)
  To: Nuno Sá, Jonathan Cameron, Liviu Stan
  Cc: Arnd Bergmann, David Lechner, Andy Shevchenko, Joshua Crofts,
	Uwe Kleine-König (The Capable Hub),
	Pan Chuang, Shi Hao, linux-iio, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

When __ltc2983_custom_sensor_new() is inlined into a caller, gcc notices
that the string compare can never succeed and warns about this being a
possible mistake:

In function '__ltc2983_custom_sensor_new',
    inlined from 'ltc2983_thermistor_new' at drivers/iio/temperature/ltc2983.c:1079:24:
drivers/iio/temperature/ltc2983.c:559:29: error: 'strcmp' of a string of length 24 and an array of size 22 evaluates to nonzero [-Werror=string-compare]
  559 |    if ((index % 2) != 0 && !strcmp(propname, "adi,custom-leak-detector"))
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is a false positive warning as the code always works correctly,
though the strcmp() is a somewhat elaborate way of identifying the caller.

Rework this by replacing both the strcmp() and the is_steinhart flag with
the sensor->type that is always available anyway and identifies with
code path gets taken.

Fixes: 3dd0c048409e ("iio: temperature: ltc2983: Add support for ADT7604")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/iio/temperature/ltc2983.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c
index 6655453c9abf..efad747c9e8d 100644
--- a/drivers/iio/temperature/ltc2983.c
+++ b/drivers/iio/temperature/ltc2983.c
@@ -482,11 +482,12 @@ static int __ltc2983_chan_custom_sensor_assign(struct ltc2983_data *st,
 
 static struct ltc2983_custom_sensor *
 __ltc2983_custom_sensor_new(struct ltc2983_data *st, const struct fwnode_handle *fn,
-			    const char *propname, const bool is_steinhart,
+			    const char *propname, int type,
 			    const u32 resolution, const bool has_signed)
 {
 	struct ltc2983_custom_sensor *new_custom;
 	struct device *dev = &st->spi->dev;
+	bool is_steinhart = type == LTC2983_SENSOR_THERMISTOR_STEINHART;
 	/*
 	 * For custom steinhart, the full u32 is taken. For all the others
 	 * the MSB is discarded.
@@ -556,7 +557,7 @@ __ltc2983_custom_sensor_new(struct ltc2983_data *st, const struct fwnode_handle
 			 * to µK so __convert_to_raw() produces the correct hardware
 			 * encoding: P + 273.15 K.
 			 */
-			if ((index % 2) != 0 && !strcmp(propname, "adi,custom-leak-detector"))
+			if ((index % 2) != 0 && type == LTC2983_SENSOR_LEAK_DETECTOR)
 				temp = temp * 1000000 + 273150000;
 
 			if ((index % 2) != 0)
@@ -846,7 +847,8 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data
 		const char *propname = "adi,custom-thermocouple";
 
 		thermo->custom = __ltc2983_custom_sensor_new(st, child,
-							     propname, false,
+							     propname,
+							     sensor->type,
 							     16384, true);
 		if (IS_ERR(thermo->custom))
 			return ERR_CAST(thermo->custom);
@@ -961,7 +963,8 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st,
 	if (sensor->type == LTC2983_SENSOR_RTD_CUSTOM) {
 		rtd->custom = __ltc2983_custom_sensor_new(st, child,
 							  "adi,custom-rtd",
-							  false, 2048, false);
+							  sensor->type,
+							  2048, false);
 		if (IS_ERR(rtd->custom))
 			return ERR_CAST(rtd->custom);
 	}
@@ -1066,11 +1069,9 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s
 
 	/* check custom sensor */
 	if (sensor->type >= LTC2983_SENSOR_THERMISTOR_STEINHART) {
-		bool steinhart = false;
 		const char *propname;
 
 		if (sensor->type == LTC2983_SENSOR_THERMISTOR_STEINHART) {
-			steinhart = true;
 			propname = "adi,custom-steinhart";
 		} else {
 			propname = "adi,custom-thermistor";
@@ -1078,7 +1079,7 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s
 
 		thermistor->custom = __ltc2983_custom_sensor_new(st, child,
 								 propname,
-								 steinhart,
+								 sensor->type,
 								 64, false);
 		if (IS_ERR(thermistor->custom))
 			return ERR_CAST(thermistor->custom);
@@ -1195,7 +1196,7 @@ ltc2983_copper_trace_new(const struct fwnode_handle *child, struct ltc2983_data
 						 "adi,custom-copper-trace is required for >1 ohm copper trace\n");
 
 		ct->custom = __ltc2983_custom_sensor_new(st, child, "adi,custom-copper-trace",
-							 false, 2048, false);
+							 sensor->type, 2048, false);
 		if (IS_ERR(ct->custom))
 			return ERR_CAST(ct->custom);
 
@@ -1286,7 +1287,7 @@ ltc2983_leak_detector_new(const struct fwnode_handle *child, struct ltc2983_data
 					 "adi,custom-leak-detector is required for leak detectors\n");
 
 	ld->custom = __ltc2983_custom_sensor_new(st, child, "adi,custom-leak-detector",
-						 false, 16, false);
+						 sensor->type, 16, false);
 	if (IS_ERR(ld->custom))
 		return ERR_CAST(ld->custom);
 
@@ -1499,7 +1500,8 @@ static struct ltc2983_sensor *ltc2983_temp_new(struct fwnode_handle *child,
 					 sensor->chan);
 
 	temp->custom = __ltc2983_custom_sensor_new(st, child, "adi,custom-temp",
-						   false, 4096, true);
+						   sensor->type,
+						   4096, true);
 	if (IS_ERR(temp->custom))
 		return ERR_CAST(temp->custom);
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-02 13:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-02 12:48 [PATCH] iio: temperature: ltc2983: avoid -Wstring-compare warning Arnd Bergmann
2026-10-02 13:04 ` Joshua Crofts
2026-10-02 13:29   ` Andy Shevchenko
2026-10-02 13:36     ` Joshua Crofts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®