From: Guenter Roeck <linux@roeck-us.net>
To: linux-hwmon@vger.kernel.org
Cc: Rob Herring <robh@kernel.org>,
linux-kernel@vger.kernel.org,
Peter Yin <peteryin.openbmc@gmail.com>,
Potin Lai <potin.lai.pt@gmail.com>,
Daniel Matyas <daniel.matyas@analog.com>,
Andrew Davis <afd@ti.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 3/4] hwmon: (pmbus/mp2856) Let enum chips start with index 0
Date: Mon, 10 Jun 2024 11:10:45 -0700 [thread overview]
Message-ID: <20240610181046.1991436-4-linux@roeck-us.net> (raw)
In-Reply-To: <20240610181046.1991436-1-linux@roeck-us.net>
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 | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/hwmon/pmbus/mp2856.c b/drivers/hwmon/pmbus/mp2856.c
index 6969350f5d7d..41bb86667091 100644
--- a/drivers/hwmon/pmbus/mp2856.c
+++ b/drivers/hwmon/pmbus/mp2856.c
@@ -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));
--
2.39.2
next prev parent reply other threads:[~2024-06-10 18:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 18:10 [PATCH 0/4] hwmon: Update handling of chip-id enums Guenter Roeck
2024-06-10 18:10 ` [PATCH 1/4] hwmon: (pmbus/lm25066) Let enum chips start with index 0 Guenter Roeck
2024-06-10 18:10 ` [PATCH 2/4] hwmon: (nct6775) Let enum kinds " Guenter Roeck
2024-06-10 18:10 ` Guenter Roeck [this message]
2024-06-10 18:10 ` [PATCH 4/4] hwmon: (pmbus/max31827) Explain why enum chips must not start with 0 Guenter Roeck
2024-06-11 9:07 ` Nuno Sá
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=20240610181046.1991436-4-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=afd@ti.com \
--cc=daniel.matyas@analog.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peteryin.openbmc@gmail.com \
--cc=potin.lai.pt@gmail.com \
--cc=robh@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox