]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (pmbus/mp2856) Let enum chips start with index 0
authorGuenter Roeck <linux@roeck-us.net>
Thu, 6 Jun 2024 16:36:38 +0000 (09:36 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 11 Jun 2024 14:25:13 +0000 (07:25 -0700)
Earlier it was assumed that the data pointer in of_device_id must not start
with 0 (NULL) if i2c_get_match_data() is used. However, it turns out that
this is perfectly fine as long as there is also an i2c_device_id array with
the same data, which is used as fallback in that case.

Let enum chips start with 0 to avoid confusion against other drivers
where the enum starts with 0 and i2c_get_match_data() is used as well.

While doing that, remove chip_id from struct mp2856_data since it is only
used in the probe function, and typecast the result of i2c_get_match_data()
to kernel_ulong_t to avoid the double typecast.

Cc: Peter Yin <peteryin.openbmc@gmail.com>
Cc: Potin Lai <potin.lai.pt@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/pmbus/mp2856.c

index 6969350f5d7d498ef74caceca5fa8e553b1f338a..41bb866670912827b759e0569286b971904cee5a 100644 (file)
@@ -46,7 +46,7 @@
 
 #define MP2856_PAGE_NUM                        2
 
-enum chips { mp2856 = 1, mp2857 };
+enum chips { mp2856, mp2857 };
 
 static const int mp2856_max_phases[][MP2856_PAGE_NUM] = {
        [mp2856] = { MP2856_MAX_PHASE_RAIL1, MP2856_MAX_PHASE_RAIL2 },
@@ -66,7 +66,6 @@ struct mp2856_data {
        int vout_format[MP2856_PAGE_NUM];
        int curr_sense_gain[MP2856_PAGE_NUM];
        int max_phases[MP2856_PAGE_NUM];
-       enum chips chip_id;
 };
 
 #define to_mp2856_data(x)      container_of(x, struct mp2856_data, info)
@@ -397,6 +396,7 @@ static int mp2856_probe(struct i2c_client *client)
 {
        struct pmbus_driver_info *info;
        struct mp2856_data *data;
+       enum chips chip_id;
        int ret;
 
        data = devm_kzalloc(&client->dev, sizeof(struct mp2856_data),
@@ -404,9 +404,9 @@ static int mp2856_probe(struct i2c_client *client)
        if (!data)
                return -ENOMEM;
 
-       data->chip_id = (enum chips)(uintptr_t)i2c_get_match_data(client);
+       chip_id = (kernel_ulong_t)i2c_get_match_data(client);
 
-       memcpy(data->max_phases, mp2856_max_phases[data->chip_id],
+       memcpy(data->max_phases, mp2856_max_phases[chip_id],
               sizeof(data->max_phases));
 
        memcpy(&data->info, &mp2856_info, sizeof(*info));