Re: [PATCH 1/1] hwmon: remove unnecessary (void*) conversions

From: Ammar Faizi
Date: Wed Jan 11 2023 - 01:09:52 EST


On 1/11/23 1:03 PM, Ammar Faizi wrote:
On 1/11/23 10:29 AM, Guenter Roeck wrote:
On 1/10/23 18:07, XU pengfei wrote:
diff --git a/drivers/hwmon/powr1220.c b/drivers/hwmon/powr1220.c
index f77dc6db31ac..501337ee5aa3 100644
--- a/drivers/hwmon/powr1220.c
+++ b/drivers/hwmon/powr1220.c
@@ -174,7 +174,7 @@ static umode_t
  powr1220_is_visible(const void *data, enum hwmon_sensor_types type, u32
              attr, int channel)
  {
-    struct powr1220_data *chip_data = (struct powr1220_data *)data;
+    struct powr1220_data *chip_data = data;

This is wrong. That cast is needed to discard the "const".

  CC [M]  drivers/hwmon/powr1220.o
drivers/hwmon/powr1220.c: In function ‘powr1220_is_visible’:
drivers/hwmon/powr1220.c:177:43: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
  177 |         struct powr1220_data *chip_data = data;
      |                                           ^~~~
cc1: all warnings being treated as errors

Anyway, powr1220_is_visible() doesn't write via that pointer, but
the local variable needs to be a const as well.

diff --git a/drivers/hwmon/powr1220.c b/drivers/hwmon/powr1220.c
index f77dc6db31ac..7cbbed5a6f5e 100644
--- a/drivers/hwmon/powr1220.c
+++ b/drivers/hwmon/powr1220.c
@@ -174,7 +174,7 @@ static umode_t
powr1220_is_visible(const void *data, enum hwmon_sensor_types type, u32
attr, int channel)
{
- struct powr1220_data *chip_data = (struct powr1220_data *)data;
+ const struct powr1220_data *chip_data = data;
if (channel >= chip_data->max_channels)
return 0;


--
Ammar Faizi