From: Arnd Bergmann <arnd@kernel.org>
To: "Nuno Sá" <nuno.sa@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Liviu Stan" <liviu.stan@analog.com>
Cc: "Arnd Bergmann" <arnd@arndb.de>,
"David Lechner" <dlechner@baylibre.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Joshua Crofts" <joshua.crofts1@gmail.com>,
"Uwe Kleine-König (The Capable Hub)"
<u.kleine-koenig@baylibre.com>, "Pan Chuang" <panchuang@vivo.com>,
"Shi Hao" <i.shihao.999@gmail.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] iio: temperature: ltc2983: avoid -Wstring-compare warning
Date: Fri, 2 Oct 2026 14:48:51 +0200 [thread overview]
Message-ID: <20261002124902.3703019-1-arnd@kernel.org> (raw)
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
next reply other threads:[~2026-10-02 12:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 12:48 Arnd Bergmann [this message]
2026-10-02 13:04 ` [PATCH] iio: temperature: ltc2983: avoid -Wstring-compare warning Joshua Crofts
2026-10-02 13:29 ` Andy Shevchenko
2026-10-02 13:36 ` Joshua Crofts
2026-10-03 17:41 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261002124902.3703019-1-arnd@kernel.org \
--to=arnd@kernel.org \
--cc=andy@kernel.org \
--cc=arnd@arndb.de \
--cc=dlechner@baylibre.com \
--cc=i.shihao.999@gmail.com \
--cc=jic23@kernel.org \
--cc=joshua.crofts1@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liviu.stan@analog.com \
--cc=nuno.sa@analog.com \
--cc=panchuang@vivo.com \
--cc=u.kleine-koenig@baylibre.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.