diff mbox series

[4/4] hwmon: (pmbus/max31827) Explain why enum chips must not start with 0

Message ID 20240610181046.1991436-5-linux@roeck-us.net (mailing list archive)
State Accepted
Headers show
Series hwmon: Update handling of chip-id enums | expand

Commit Message

Guenter Roeck June 10, 2024, 6:10 p.m. UTC
If a driver calls device_get_match_data(), the .data pointer in its id
data structures must not be NULL/0 because device_get_match_data()
returns NULL if an entry is not found. Explain that in a comment to avoid
confusion why this is required in this driver but not in other drivers.

Cc: Daniel Matyas <daniel.matyas@analog.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/max31827.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Nuno Sá June 11, 2024, 9:07 a.m. UTC | #1
On Mon, 2024-06-10 at 11:10 -0700, Guenter Roeck wrote:
> If a driver calls device_get_match_data(), the .data pointer in its id
> data structures must not be NULL/0 because device_get_match_data()
> returns NULL if an entry is not found. Explain that in a comment to avoid
> confusion why this is required in this driver but not in other drivers.
> 
> Cc: Daniel Matyas <daniel.matyas@analog.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

Acked-by: Nuno Sa <nuno.sa@analog.com>

>  drivers/hwmon/max31827.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/hwmon/max31827.c b/drivers/hwmon/max31827.c
> index f8a13b30f100..391cb059e94d 100644
> --- a/drivers/hwmon/max31827.c
> +++ b/drivers/hwmon/max31827.c
> @@ -46,6 +46,11 @@
>  #define MAX31827_M_DGR_TO_16_BIT(x)	(((x) << 4) / 1000)
>  #define MAX31827_DEVICE_ENABLE(x)	((x) ? 0xA : 0x0)
>  
> +/*
> + * The enum passed in the .data pointer of struct of_device_id must
> + * start with a value != 0 since that is a requirement for using
> + * device_get_match_data().
> + */
>  enum chips { max31827 = 1, max31828, max31829 };
>  
>  enum max31827_cnv {
diff mbox series

Patch

diff --git a/drivers/hwmon/max31827.c b/drivers/hwmon/max31827.c
index f8a13b30f100..391cb059e94d 100644
--- a/drivers/hwmon/max31827.c
+++ b/drivers/hwmon/max31827.c
@@ -46,6 +46,11 @@ 
 #define MAX31827_M_DGR_TO_16_BIT(x)	(((x) << 4) / 1000)
 #define MAX31827_DEVICE_ENABLE(x)	((x) ? 0xA : 0x0)
 
+/*
+ * The enum passed in the .data pointer of struct of_device_id must
+ * start with a value != 0 since that is a requirement for using
+ * device_get_match_data().
+ */
 enum chips { max31827 = 1, max31828, max31829 };
 
 enum max31827_cnv {