pci: use kstrtobool over ad hoc string parsing

Message ID 20180212230457.23181-1-kballou@devnulllabs.io
State New
Headers show
Series
  • pci: use kstrtobool over ad hoc string parsing
Related show

Commit Message

Kenny Ballou Feb. 12, 2018, 11:04 p.m.
Convert ROM read access enable/disable string parsing to use the
`kstrtobool` function.

This fixes Bugzilla Bug 111301 -- Sysfs PCI rom file functionality does
not match documentation.

bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=111301

Reported-by: googlegot@yahoo.com
Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
---
 drivers/pci/pci-sysfs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Kenny Ballou Feb. 19, 2018, 8:56 p.m. | #1
On 2018年02月12日 23:04 GMT, Kenny Ballou wrote:
> Convert ROM read access enable/disable string parsing to use the
> `kstrtobool` function.
>
> This fixes Bugzilla Bug 111301 -- Sysfs PCI rom file functionality does
> not match documentation.
>
> bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=111301
>
> Reported-by: googlegot@yahoo.com
> Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
> ---
>  drivers/pci/pci-sysfs.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index eb6bee8724cc..3cde1f25e786 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1424,10 +1424,12 @@ static ssize_t pci_write_rom(struct file *filp, struct kobject *kobj,
>  {
>  	struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
>  
> -	if ((off ==  0) && (*buf == '0') && (count == 2))
> -		pdev->rom_attr_enabled = 0;
> -	else
> +	bool res = false;
> +
> +	if (kstrtobool(buf, &res) == 0 && res)
>  		pdev->rom_attr_enabled = 1;
> +	else
> +		pdev->rom_attr_enabled = 0;
>  
>  	return count;
>  }

Bjorn,

How does one know if a patch was accepted?  Should I be monitoring
patchwork?  What's the status of the quoted patch?  Patchwork doesn't
seem to show any changes for this patch.

Regards,
-Kenny
Bjorn Helgaas Feb. 19, 2018, 9:10 p.m. | #2
On Mon, Feb 19, 2018 at 2:56 PM, Kenny Ballou <kballou@devnulllabs.io> wrote:
>
> On 2018年02月12日 23:04 GMT, Kenny Ballou wrote:
>> Convert ROM read access enable/disable string parsing to use the
>> `kstrtobool` function.
>>
>> This fixes Bugzilla Bug 111301 -- Sysfs PCI rom file functionality does
>> not match documentation.
>>
>> bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=111301
>>
>> Reported-by: googlegot@yahoo.com
>> Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
>> ---
>>  drivers/pci/pci-sysfs.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
>> index eb6bee8724cc..3cde1f25e786 100644
>> --- a/drivers/pci/pci-sysfs.c
>> +++ b/drivers/pci/pci-sysfs.c
>> @@ -1424,10 +1424,12 @@ static ssize_t pci_write_rom(struct file *filp, struct kobject *kobj,
>>  {
>>       struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
>>
>> -     if ((off ==  0) && (*buf == '0') && (count == 2))
>> -             pdev->rom_attr_enabled = 0;
>> -     else
>> +     bool res = false;
>> +
>> +     if (kstrtobool(buf, &res) == 0 && res)
>>               pdev->rom_attr_enabled = 1;
>> +     else
>> +             pdev->rom_attr_enabled = 0;
>>
>>       return count;
>>  }
>
> Bjorn,
>
> How does one know if a patch was accepted?  Should I be monitoring
> patchwork?  What's the status of the quoted patch?  Patchwork doesn't
> seem to show any changes for this patch.

When I apply or review a patch, I always respond to the original email
posting of it.  So you don't need to do anything more; I just haven't
gotten to this one.  I don't see any real issues with this, although
I'll probably expand the changelog to contain a little more detail
about exactly what the problem is and how this fixes it.  The bugzilla
link is great but the changelog itself should have enough information
to justify the change.

Bjorn

Patch

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index eb6bee8724cc..3cde1f25e786 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1424,10 +1424,12 @@  static ssize_t pci_write_rom(struct file *filp, struct kobject *kobj,
 {
 	struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
 
-	if ((off ==  0) && (*buf == '0') && (count == 2))
-		pdev->rom_attr_enabled = 0;
-	else
+	bool res = false;
+
+	if (kstrtobool(buf, &res) == 0 && res)
 		pdev->rom_attr_enabled = 1;
+	else
+		pdev->rom_attr_enabled = 0;
 
 	return count;
 }