PATCH: f71882fg move some io access from the detect to
The f71882fg driver did some io to ioports it hadn't reserved yet in its find (detect) function, this patches moves this io to the probe function where these ports are reserved and this io belongs.
The f71882fg driver did some io to ioports it hadn't reserved yet in its find (detect) function, this patches moves this io to the probe function where these ports are reserved and this io belongs.
drivers/hwmon/f71882fg.c renamed from drivers/hwmon/f71882fg.c.f71862fg +24 -24
@@ -1495,7 +1495,7 @@ {struct f71882fg_data *data;struct f71882fg_sio_data *sio_data = pdev->dev.platform_data; -int err; +int err =0 ;u8 start_reg; data =kzalloc (sizeof (struct f71882fg_data ),GFP_KERNEL );
@@ -1507,12 +1507,31 @@mutex_init (&data->update_lock);platform_set_drvdata (pdev, data); + start_reg =f71882fg_read8 (data,F71882FG_REG_START ); +if (!(start_reg &0x03 )) { + printk(KERN_WARNING DRVNAME + ": Hardware monitoring not activated\n"); + goto exit_free; + } + +/* If it is a 71862 and the fan / pwm part is enabled sanity check +the pwm settings */ +if (data->type == f71862fg && (start_reg &0x02 )) { +u8 reg =f71882fg_read8 (data,F71882FG_REG_PWM_ENABLE ); +if ((reg &0x15 ) !=0x15 ) { + printk(KERN_ERR DRVNAME +": Invalid (reserved) pwm settings: 0x%02x\n" , + (unsigned int)reg); + err = -EIO ; + goto exit_free; + } + } +/* Register sysfs interface files */ err =device_create_file (&pdev->dev, &dev_attr_name);if (err) goto exit_unregister_sysfs; - start_reg =f71882fg_read8 (data,F71882FG_REG_START );if (start_reg &0x01 ) { err =f71882fg_create_sysfs_files (pdev, f718x2fg_in_temp_attr,ARRAY_SIZE (f718x2fg_in_temp_attr));
@@ -1558,7 +1577,9 @@ exit_unregister_sysfs:f71882fg_remove (pdev);/* Will unregister the sysfs files for us */ - +return err;/* f71882fg_remove() also frees our data */ +exit_free: +kfree (data);return err; }
@@ -1600,8 +1621,6 @@ {int err = -ENODEV ;u16 devid; -u8 reg; -struct f71882fg_data data;superio_enter (sioaddr);
@@ -1638,25 +1657,6 @@ } *address &= ~(REGION_LENGTH -1 );/* Ignore 3 LSB */ - data.addr = *address; - reg =f71882fg_read8 (&data,F71882FG_REG_START ); -if (!(reg &0x03 )) { - printk(KERN_WARNING DRVNAME - ": Hardware monitoring not activated\n"); - goto exit; - } - -/* If it is a 71862 and the fan / pwm part is enabled sanity check -the pwm settings */ -if (sio_data->type == f71862fg && (reg &0x02 )) { - reg =f71882fg_read8 (&data,F71882FG_REG_PWM_ENABLE ); -if ((reg &0x15 ) !=0x15 ) { - printk(KERN_ERR DRVNAME -": Invalid (reserved) pwm settings: 0x%02x\n" , - (unsigned int)reg); - goto exit; - } - } err =0 ; printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %d\n", f71882fg_names[sio_data->type], (unsigned int)*address,
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] PATCH: f71882fg move some io access from the
Hi Hans,
Quoted 5 lines · Hans de Goede
The f71882fg driver did some io to ioports it hadn't reserved yet in its find (detect) function, this patches moves this io to the probe function where these ports are reserved and this io belongs.
Signed-off-by Hans de Goede <[email protected]>
Review:
Quoted 17 lines
The f71882fg driver did some io to ioports it hadn't reserved yet in its find (detect) function, this patches moves this io to the probe function where these ports are reserved and this io belongs.
Signed-off-by Hans de Goede <[email protected]>drivers/hwmon/f71882fg.c renamed from drivers/hwmon/f71882fg.c.f71862fg +1
-1@@ -1495,7 +1495,7 @@ {struct f71882fg_data *data;struct f71882fg_sio_data *sio_data = pdev->dev.platform_data; -int err; +int err =0 ;u8 start_reg; data =kzalloc (sizeof (struct f71882fg_data ),GFP_KERNEL );
drivers/hwmon/f71882fg.c line 1513
Quoted 7 lines
drivers/hwmon/f71882fg.c renamed from drivers/hwmon/f71882fg.c.f71862fg +4
-0@@ -1507,12 +1507,31 @@mutex_init (&data->update_lock);platform_set_drvdata (pdev, data); + start_reg =f71882fg_read8 (data,F71882FG_REG_START ); +if (!(start_reg &0x03 )) { + printk(KERN_WARNING DRVNAME + ": Hardware monitoring not activated\n");
Please use dev_info() instead.
drivers/hwmon/f71882fg.c line 1514
Quoted 1 line
drivers/hwmon/f71882fg.c renamed from drivers/hwmon/f71882fg.c.f71862fg +1
-0+ goto exit_free;
You're returning with err = 0, which means success. So when you unload the driver, the f71882fg_remove() function will be called and you'll double-free your private data structure. No good.
I think you should simply return -ENODEV here.
drivers/hwmon/f71882fg.c line 1524
Quoted 10 lines
drivers/hwmon/f71882fg.c renamed from drivers/hwmon/f71882fg.c.f71862fg +10
-0+ } + +/* If it is a 71862 and the fan / pwm part is enabled sanity check +the pwm settings */ +if (data->type = f71862fg && (start_reg &0x02 )) { +u8 reg =f71882fg_read8 (data,F71882FG_REG_PWM_ENABLE ); +if ((reg &0x15 ) !=0x15 ) { + printk(KERN_ERR DRVNAME +": Invalid (reserved) pwm settings: 0x%02x\n" , + (unsigned int)reg);
Here again please use dev_err().
drivers/hwmon/f71882fg.c line 1525
Quoted 1 line
drivers/hwmon/f71882fg.c renamed from drivers/hwmon/f71882fg.c.f71862fg +1
-0+ err = -EIO ;
This isn't actually an I/O error, I think I'd return -ENODEV as well. Or, ideally, you could simply disable the pwm features of the driver but still let it bind. After all, voltage, temperature and fan features are still useful, aren't they?
Quoted 59 lines
drivers/hwmon/f71882fg.c renamed from drivers/hwmon/f71882fg.c.f71862fg +7
-23+ goto exit_free; + } + } +/* Register sysfs interface files */ err =device_create_file (&pdev->dev, &dev_attr_name);if (err) goto exit_unregister_sysfs; - start_reg =f71882fg_read8 (data,F71882FG_REG_START );if (start_reg &0x01 ) { err =f71882fg_create_sysfs_files (pdev, f718x2fg_in_temp_attr,ARRAY_SIZE (f718x2fg_in_temp_attr));@@ -1558,7 +1577,9 @@ exit_unregister_sysfs:f71882fg_remove (pdev);/* Will unregister the sysfs files for us */ - +return err;/* f71882fg_remove() also frees our data */ +exit_free: +kfree (data);return err; }@@ -1600,8 +1621,6 @@ {int err = -ENODEV ;u16 devid; -u8 reg; -struct f71882fg_data data;superio_enter (sioaddr);@@ -1638,25 +1657,6 @@ } *address &= ~(REGION_LENGTH -1 );/* Ignore 3 LSB */ - data.addr = *address; - reg =f71882fg_read8 (&data,F71882FG_REG_START ); -if (!(reg &0x03 )) { - printk(KERN_WARNING DRVNAME - ": Hardware monitoring not activated\n"); - goto exit; - } - -/* If it is a 71862 and the fan / pwm part is enabled sanity check -the pwm settings */ -if (sio_data->type = f71862fg && (reg &0x02 )) { - reg =f71882fg_read8 (&data,F71882FG_REG_PWM_ENABLE ); -if ((reg &0x15 ) !=0x15 ) { - printk(KERN_ERR DRVNAME -": Invalid (reserved) pwm settings: 0x%02x\n" , - (unsigned int)reg); - goto exit; - } - } err =0 ; printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %d\n", f71882fg_names[sio_data->type], (unsigned int)*address,
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] PATCH: f71882fg move some io access from the
In reply to Hans de GoedeQuoted 11 lines · Jean Delvare
Hi Hans,
Quoted 5 lines · Hans de Goede
The f71882fg driver did some io to ioports it hadn't reserved yet in its find (detect) function, this patches moves this io to the probe function where these ports are reserved and this io belongs.
Signed-off-by Hans de Goede <[email protected]>Review:
<snip>
Quoted 11 lines
Review line 1513
Quoted 8 lines
(quoted diff) +4
-0@@ -1507,12 +1507,31 @@ mutex_init(&data->update_lock); platform_set_drvdata(pdev, data); + start_reg = f71882fg_read8(data, F71882FG_REG_START); + if (!(start_reg & 0x03)) { + printk(KERN_WARNING DRVNAME + ": Hardware monitoring not activated\n");Please use
dev_info()instead.
Done.
Quoted 8 lines
Review line 1514
Quoted 1 line
(quoted diff) +1
-0+ goto exit_free;You're returning with err = 0, which means success. So when you unload the driver, the
f71882fg_remove()function will be called and you'll double-free your private data structure. No good.I think you should simply return
-ENODEVhere.
Done.
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+ } + + /* If it is a 71862 and the fan / pwm part is enabled sanity check + the pwm settings */
Quoted 9 lines
Review line 1524
Quoted 6 lines
(quoted diff) +6
-0+ if (data->type == f71862fg && (start_reg & 0x02)) { + u8 reg = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); + if ((reg & 0x15) != 0x15) { + printk(KERN_ERR DRVNAME + ": Invalid (reserved) pwm settings: 0x%02x\n", + (unsigned int)reg);Here again please use
dev_err().
Done.
Quoted 3 lines
Review line 1525
Quoted 1 line
(quoted diff) +1
-0+ err = -EIO;This isn't actually an I/O error, I think I'd return
-ENODEVas well.
Done.
Quoted 4 lines
Or, ideally, you could simply disable the pwm features of the driver but still let it bind. After all, voltage, temperature and fan features are still useful, aren't they?
This is a should never happen case, those bits I'm testing are reserved and should always be 1, the reason I'm testing them is because the 71862 only has PWM auto fan control, where as the 71882 has both PWM and RPM modes, the code paths used by both check these bits to see if the chip is in RPM or PWM mode, so if these *reserved* bits have the wrong value, the RPM mode code path can be entered on the 71862.
Even more troublesome is that as the 71862 clearly is a stripped down 71882 the chip itself may behave funny if programmed to be in the removed RPM modes. So I rather just bail completely when this register shows the should never happen readings. If this message gets triggered ever (and reported) we can revisit this.
I've attached an updated version of the patch.
Regards,
Hans
The f71882fg driver did some io to ioports it hadn't reserved yet in its find (detect) function, this patches moves this io to the probe function where these ports are reserved and this io belongs.
f71882fg.c renamed from f71882fg.c.f71862fg +23 -23
@@ -1507,12 +1507,31 @@mutex_init (&data->update_lock);platform_set_drvdata (pdev, data); + start_reg =f71882fg_read8 (data,F71882FG_REG_START ); +if (!(start_reg &0x03 )) { +dev_info (&pdev->dev,": Hardware monitoring not activated\n" ); + err = -ENODEV ; + goto exit_free; + } + +/* If it is a 71862 and the fan / pwm part is enabled sanity check +the pwm settings */ +if (data->type == f71862fg && (start_reg &0x02 )) { +u8 reg =f71882fg_read8 (data,F71882FG_REG_PWM_ENABLE ); +if ((reg &0x15 ) !=0x15 ) { +dev_err (&pdev->dev, +": Invalid (reserved) pwm settings: 0x%02x\n" , + (unsigned int )reg); + err = -ENODEV ; + goto exit_free; + } + } +/* Register sysfs interface files */ err =device_create_file (&pdev->dev, &dev_attr_name);if (err) goto exit_unregister_sysfs; - start_reg =f71882fg_read8 (data,F71882FG_REG_START );if (start_reg &0x01 ) { err =f71882fg_create_sysfs_files (pdev, f718x2fg_in_temp_attr,ARRAY_SIZE (f718x2fg_in_temp_attr));
@@ -1558,7 +1577,9 @@ exit_unregister_sysfs:f71882fg_remove (pdev);/* Will unregister the sysfs files for us */ - +return err;/* f71882fg_remove() also frees our data */ +exit_free: +kfree (data);return err; }
@@ -1600,8 +1621,6 @@ {int err = -ENODEV ;u16 devid; -u8 reg; -struct f71882fg_data data;superio_enter (sioaddr);
@@ -1638,25 +1657,6 @@ } *address &= ~(REGION_LENGTH -1 );/* Ignore 3 LSB */ - data.addr = *address; - reg =f71882fg_read8 (&data,F71882FG_REG_START ); -if (!(reg &0x03 )) { - printk(KERN_WARNING DRVNAME - ": Hardware monitoring not activated\n"); - goto exit; - } - -/* If it is a 71862 and the fan / pwm part is enabled sanity check -the pwm settings */ -if (sio_data->type == f71862fg && (reg &0x02 )) { - reg =f71882fg_read8 (&data,F71882FG_REG_PWM_ENABLE ); -if ((reg &0x15 ) !=0x15 ) { - printk(KERN_ERR DRVNAME -": Invalid (reserved) pwm settings: 0x%02x\n" , - (unsigned int)reg); - goto exit; - } - } err =0 ; printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %d\n", f71882fg_names[sio_data->type], (unsigned int)*address,
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] PATCH: f71882fg move some io access from the
In reply to Hans de GoedeHi Hans,
Quoted 19 lines · Hans de Goede
Quoted 11 lines · Jean Delvare
Hi Hans,
Quoted 5 lines · Hans de Goede
The f71882fg driver did some io to ioports it hadn't reserved yet in its find (detect) function, this patches moves this io to the probe function where these ports are reserved and this io belongs.
Signed-off-by Hans de Goede <[email protected]>Review:
<snip>
Quoted 4 lines
Quoted 4 lines
drivers/hwmon/f71882fg.c renamed from drivers/hwmon/f71882fg.c.f71862fg +0
-0@@ -1507,12 +1507,31 @@mutex_init (&data->update_lock);platform_set_drvdata (pdev, data);
Quoted 8 lines
Quoted 6 lines
drivers/hwmon/f71882fg.c line 1513
Quoted 4 lines
drivers/hwmon/f71882fg.c renamed from drivers/hwmon/f71882fg.c.f71862fg +4
-0+ start_reg =f71882fg_read8 (data,F71882FG_REG_START ); +if (!(start_reg &0x03 )) { + printk(KERN_WARNING DRVNAME + ": Hardware monitoring not activated\n");Please use
dev_info()instead.Done.
I really meant dev_warn(), sorry. I'll fix that myself.
Quoted 12 lines
Quoted 4 lines
(...)
Or, ideally, you could simply disable the pwm features of the driver but still let it bind. After all, voltage, temperature and fan features are still useful, aren't they?This is a should never happen case, those bits I'm testing are reserved and should always be 1, the reason I'm testing them is because the 71862 only has PWM auto fan control, where as the 71882 has both PWM and RPM modes, the code paths used by both check these bits to see if the chip is in RPM or PWM mode, so if these *reserved* bits have the wrong value, the RPM mode code path can be entered on the 71862.
Quoted 4 lines
Even more troublesome is that as the 71862 clearly is a stripped down 71882 the chip itself may behave funny if programmed to be in the removed RPM modes. So I rather just bail completely when this register shows the should never happen readings. If this message gets triggered ever (and reported) we can revisit this.
OK, fine with me.
f71882fg.c
Quoted 9 lines
I've attached an updated version of the patch.
(...)
The f71882fg driver did some io to ioports it hadn't reserved yet in its find (detect) function, this patches moves this io to the probe function where these ports are reserved and this io belongs.Signed-off-by Hans de Goede <[email protected]>f71882fg.c renamed from f71882fg.c.f71862fg +0
-0
You don't like paths, hmm? ;)
Really, you should use quilt. That would solve this problem.
Quoted 9 lines
f71882fg.c renamed from f71882fg.c.f71862fg +5
-0@@ -1507,12 +1507,31 @@mutex_init (&data->update_lock);platform_set_drvdata (pdev, data); + start_reg =f71882fg_read8 (data,F71882FG_REG_START ); +if (!(start_reg &0x03 )) { +dev_info (&pdev->dev,": Hardware monitoring not activated\n" ); + err = -ENODEV ; + goto exit_free;
f71882fg.c line 1524
Quoted 10 lines
f71882fg.c renamed from f71882fg.c.f71862fg +10
-0+ } + +/* If it is a 71862 and the fan / pwm part is enabled sanity check +the pwm settings */ +if (data->type = f71862fg && (start_reg &0x02 )) { +u8 reg =f71882fg_read8 (data,F71882FG_REG_PWM_ENABLE ); +if ((reg &0x15 ) !=0x15 ) { +dev_err (&pdev->dev, +": Invalid (reserved) pwm settings: 0x%02x\n" , + (unsigned int )reg);
dev_*() calls already include a colon, so no need to add one. I'll fix that myself, no need to resend.
Quoted 60 lines
f71882fg.c renamed from f71882fg.c.f71862fg +8
-23+ err = -ENODEV ; + goto exit_free; + } + } +/* Register sysfs interface files */ err =device_create_file (&pdev->dev, &dev_attr_name);if (err) goto exit_unregister_sysfs; - start_reg =f71882fg_read8 (data,F71882FG_REG_START );if (start_reg &0x01 ) { err =f71882fg_create_sysfs_files (pdev, f718x2fg_in_temp_attr,ARRAY_SIZE (f718x2fg_in_temp_attr));@@ -1558,7 +1577,9 @@ exit_unregister_sysfs:f71882fg_remove (pdev);/* Will unregister the sysfs files for us */ - +return err;/* f71882fg_remove() also frees our data */ +exit_free: +kfree (data);return err; }@@ -1600,8 +1621,6 @@ {int err = -ENODEV ;u16 devid; -u8 reg; -struct f71882fg_data data;superio_enter (sioaddr);@@ -1638,25 +1657,6 @@ } *address &= ~(REGION_LENGTH -1 );/* Ignore 3 LSB */ - data.addr = *address; - reg =f71882fg_read8 (&data,F71882FG_REG_START ); -if (!(reg &0x03 )) { - printk(KERN_WARNING DRVNAME - ": Hardware monitoring not activated\n"); - goto exit; - } - -/* If it is a 71862 and the fan / pwm part is enabled sanity check -the pwm settings */ -if (sio_data->type = f71862fg && (reg &0x02 )) { - reg =f71882fg_read8 (&data,F71882FG_REG_PWM_ENABLE ); -if ((reg &0x15 ) !=0x15 ) { - printk(KERN_ERR DRVNAME -": Invalid (reserved) pwm settings: 0x%02x\n" , - (unsigned int)reg); - goto exit; - } - } err =0 ; printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %d\n", f71882fg_names[sio_data->type], (unsigned int)*address,
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] PATCH: f71882fg move some io access from the
In reply to Hans de GoedeQuoted 9 lines · Jean Delvare
Hi Hans,
Quoted 3 lines · Hans de Goede
Quoted 1 line · Jean Delvare
Please use
dev_info()instead.Done.
I really meant
dev_warn(), sorry. I'll fix that myself.
I _really_ should have figured that out myself.
<snip>
Quoted 7 lines
f71882fg.c
Quoted 3 lines
Signed-off-by Hans de Goede <[email protected]>f71882fg.c renamed from f71882fg.c.f71862fg +0
-0You don't like paths, hmm? ;)
Really, you should use quilt. That would solve this problem.
I hear lots of good things about quilt I'll try to use it next time around.
Thanks & Regards,
Hans
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] PATCH: f71882fg move some io access from the
In reply to Hans de GoedeHi Hans,
Quoted 4 lines · Hans de Goede
Quoted 1 line · Jean Delvare
Really, you should use quilt. That would solve this problem.
I hear lots of good things about quilt I'll try to use it next time around.
That's really easy:
$ quilt new hwmon-f71882fg-fix-stuff.patch $ quilt add drivers/hwmon/f71882fg.c # Edit the file, build, test, etc. $ quilt diff # See your changes $ quilt refresh # Write them to the disk $ quilt head -e # Describe the patch and add your Signed-off-by
And send patches/hwmon-f71882fg-fix-stuff.patch.
Here's my ~/.quiltrc if you want to see what I consider sane defaults:
QUILT_REFRESH_ARGS="--diffstat --strip-trailing-whitespace" QUILT_DIFF_ARGS="--color"
QUILT_DIFF_OPTS="-p"
QUILT_NO_DIFF_INDEX=1
EDITOR=nedit
If you need help with quilt, just ask, I'll be happy to help you get up to speed quickly.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors