linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: Remove checks for validity of dev
@ 2022-01-28 12:59 Muhammad Usama Anjum
  2022-01-28 15:05 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Muhammad Usama Anjum @ 2022-01-28 12:59 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck
  Cc: Muhammad Usama Anjum, kernel, kernel-janitors, linux-hwmon, linux-kernel

dev is being dereferenced in device_property_present() which means that
it is valid. Don't check its validity again and simplify the code.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
 drivers/hwmon/hwmon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index e36ea82da1474..aec32abd0a89f 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -822,7 +822,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
 	hwdev->name = name;
 	hdev->class = &hwmon_class;
 	hdev->parent = dev;
-	hdev->of_node = dev ? dev->of_node : NULL;
+	hdev->of_node = dev->of_node;
 	hwdev->chip = chip;
 	dev_set_drvdata(hdev, drvdata);
 	dev_set_name(hdev, HWMON_ID_FORMAT, id);
@@ -834,7 +834,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
 
 	INIT_LIST_HEAD(&hwdev->tzdata);
 
-	if (dev && dev->of_node && chip && chip->ops->read &&
+	if (dev->of_node && chip && chip->ops->read &&
 	    chip->info[0]->type == hwmon_chip &&
 	    (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
 		err = hwmon_thermal_register_sensors(hdev);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hwmon: Remove checks for validity of dev
  2022-01-28 12:59 [PATCH] hwmon: Remove checks for validity of dev Muhammad Usama Anjum
@ 2022-01-28 15:05 ` Guenter Roeck
  2022-01-28 16:59   ` Muhammad Usama Anjum
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2022-01-28 15:05 UTC (permalink / raw)
  To: Muhammad Usama Anjum, Jean Delvare
  Cc: kernel, kernel-janitors, linux-hwmon, linux-kernel

On 1/28/22 04:59, Muhammad Usama Anjum wrote:
> dev is being dereferenced in device_property_present() which means that
> it is valid. Don't check its validity again and simplify the code.
> 
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
>   drivers/hwmon/hwmon.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index e36ea82da1474..aec32abd0a89f 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -822,7 +822,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
>   	hwdev->name = name;
>   	hdev->class = &hwmon_class;
>   	hdev->parent = dev;
> -	hdev->of_node = dev ? dev->of_node : NULL;
> +	hdev->of_node = dev->of_node;
>   	hwdev->chip = chip;
>   	dev_set_drvdata(hdev, drvdata);
>   	dev_set_name(hdev, HWMON_ID_FORMAT, id);
> @@ -834,7 +834,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
>   
>   	INIT_LIST_HEAD(&hwdev->tzdata);
>   
> -	if (dev && dev->of_node && chip && chip->ops->read &&
> +	if (dev->of_node && chip && chip->ops->read &&
>   	    chip->info[0]->type == hwmon_chip &&
>   	    (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
>   		err = hwmon_thermal_register_sensors(hdev);

Wrong fix, sorry. While I would love to make dev mandatory, the function
is called with dev == NULL from at least one place, and the check is (still)
needed. Even if/when it is removed we would have to add an early check
and return -EINVAL if it is NULL.

Guenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hwmon: Remove checks for validity of dev
  2022-01-28 15:05 ` Guenter Roeck
@ 2022-01-28 16:59   ` Muhammad Usama Anjum
  0 siblings, 0 replies; 3+ messages in thread
From: Muhammad Usama Anjum @ 2022-01-28 16:59 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare
  Cc: usama.anjum, kernel, kernel-janitors, linux-hwmon, linux-kernel

On 1/28/22 8:05 PM, Guenter Roeck wrote:
> On 1/28/22 04:59, Muhammad Usama Anjum wrote:
>> dev is being dereferenced in device_property_present() which means that
>> it is valid. Don't check its validity again and simplify the code.
>>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>> ---
>>   drivers/hwmon/hwmon.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
>> index e36ea82da1474..aec32abd0a89f 100644
>> --- a/drivers/hwmon/hwmon.c
>> +++ b/drivers/hwmon/hwmon.c
>> @@ -822,7 +822,7 @@ __hwmon_device_register(struct device *dev, const
>> char *name, void *drvdata,
>>       hwdev->name = name;
>>       hdev->class = &hwmon_class;
>>       hdev->parent = dev;
>> -    hdev->of_node = dev ? dev->of_node : NULL;
>> +    hdev->of_node = dev->of_node;
>>       hwdev->chip = chip;
>>       dev_set_drvdata(hdev, drvdata);
>>       dev_set_name(hdev, HWMON_ID_FORMAT, id);
>> @@ -834,7 +834,7 @@ __hwmon_device_register(struct device *dev, const
>> char *name, void *drvdata,
>>         INIT_LIST_HEAD(&hwdev->tzdata);
>>   -    if (dev && dev->of_node && chip && chip->ops->read &&
>> +    if (dev->of_node && chip && chip->ops->read &&
>>           chip->info[0]->type == hwmon_chip &&
>>           (chip->info[0]->config[0] & HWMON_C_REGISTER_TZ)) {
>>           err = hwmon_thermal_register_sensors(hdev);
> 
> Wrong fix, sorry. While I would love to make dev mandatory, the function
> is called with dev == NULL from at least one place, and the check is
> (still)
> needed. Even if/when it is removed we would have to add an early check
> and return -EINVAL if it is NULL.
> 
Thank you for the reply. I've looked at the code again. You are correct.

> Guenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-28 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28 12:59 [PATCH] hwmon: Remove checks for validity of dev Muhammad Usama Anjum
2022-01-28 15:05 ` Guenter Roeck
2022-01-28 16:59   ` Muhammad Usama Anjum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).