i2c: amd8111: Remove spaces in MODULE_* macros
PATCH 1/2 i2c: amd8111: Remove spaces in MODULE_* macros
Remove space between function name and open parenthesis in MODULE_DEVICE_TABLE and MODULE_AUTHOR to comply with kernel coding style.
--- drivers/i2c/busses/i2c-amd8111.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-amd8111.c +2 -2
@@ -17,7 +17,7 @@#include <linux/io.h> MODULE_LICENSE ("GPL" ); -MODULE_AUTHOR ("Vojtech Pavlik <[email protected]>" ); +MODULE_AUTHOR ("Vojtech Pavlik <[email protected]>" );MODULE_DESCRIPTION ("AMD8111 SMBus 2.0 driver" );struct amd_smbus {
@@ -417,7 +417,7 @@ static const struct pci_device_id amd8111_ids[] = { { 0, } }; -MODULE_DEVICE_TABLE (pci, amd8111_ids); +MODULE_DEVICE_TABLE (pci, amd8111_ids);static int amd8111_probe (struct pci_dev *dev,const struct pci_device_id *id) {
Signature · 1 line
2.52.0
PATCH 2/2 i2c: amd8111: switch to devm_ functions
Use devm_kzalloc() to manage the memory allocation of the smbus structure and devm_request_region() to manage the I/O port region.
This simplifies the error handling paths in the probe function by removing manual cleanup and allows for the removal of the explicit cleanup in the remove function.
--- drivers/i2c/busses/i2c-amd8111.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-)
drivers/i2c/busses/i2c-amd8111.c +7 -19
@@ -427,7 +427,7 @@ static int amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id)if (!(pci_resource_flags (dev,0 ) &IORESOURCE_IO ))return -ENODEV ; - smbus =kzalloc (sizeof (struct amd_smbus ),GFP_KERNEL ); + smbus =devm_kzalloc (&dev->dev,sizeof (struct amd_smbus ),GFP_KERNEL );if (!smbus)return -ENOMEM ;
@@ -436,19 +436,15 @@ static int amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id) smbus->size =pci_resource_len (dev,0 ); error =acpi_check_resource_conflict (&dev->resource[0 ]); -if (error) { - error = -ENODEV ; - goto out_kfree; - } +if (error) +return -ENODEV ; -if (!request_region (smbus->base, smbus->size, amd8111_driver.name)) { - error = -EBUSY ; - goto out_kfree; - } +if (!devm_request_region (&dev->dev, smbus->base, smbus->size, amd8111_driver.name)) +return -EBUSY ; smbus->adapter.owner =THIS_MODULE ;snprintf (smbus->adapter.name,sizeof (smbus->adapter.name), -"SMBus2 AMD8111 adapter at %04x" , smbus->base); +"SMBus2 AMD8111 adapter at %04x" , smbus->base); smbus->adapter.class =I2C_CLASS_HWMON ; smbus->adapter.algo = &smbus_algorithm; smbus->adapter.algo_data = smbus;
@@ -459,16 +455,10 @@ static int amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id)pci_write_config_dword (smbus->dev,AMD_PCI_MISC ,0 ); error =i2c_add_adapter (&smbus->adapter);if (error) - goto out_release_region; +return error;pci_set_drvdata (dev, smbus);return 0 ; - - out_release_region: -release_region (smbus->base, smbus->size); - out_kfree: -kfree (smbus); -return error; }static void amd8111_remove (struct pci_dev *dev)
@@ -476,8 +466,6 @@ static void amd8111_remove(struct pci_dev *dev)struct amd_smbus *smbus =pci_get_drvdata (dev);i2c_del_adapter (&smbus->adapter); -release_region (smbus->base, smbus->size); -kfree (smbus); }static struct pci_driver amd8111_driver = {
Signature · 1 line
2.52.0
Re: [PATCH 2/2] i2c: amd8111: switch to devm_ functions
Hi Filippo,
Quoted 2 lines · Filippo Muscherà
Use
devm_kzalloc()to manage the memory allocation of the smbus structure anddevm_request_region()to manage the I/O port region.
Merged to i2c/i2c-host-2.
Just a few notes for the next time:
1. I prefer two different patches for devm_kzalloc() and devm_request_region().
2. For series with more than one patch, I'd like to have a cover letter to introduce the series.
Thanks,
Andi
Quoted 5 lines
This simplifies the error handling paths in the probe function by removing manual cleanup and allows for the removal of the explicit cleanup in the remove function.
Signed-off-by Filippo Muscherà <[email protected]>
Re: [PATCH 2/2] i2c: amd8111: switch to devm_ functions
Quoted 10 lines · Andi Shyti
Hi Filippo,
Quoted 2 lines · Filippo Muscherà
Use
devm_kzalloc()to manage the memory allocation of the smbus structure anddevm_request_region()to manage the I/O port region.Merged to i2c/i2c-host-2.
Just a few notes for the next time:
Quoted 8 lines
1. I prefer two different patches for
devm_kzalloc()anddevm_request_region().2. For series with more than one patch, I'd like to have a cover letter to introduce the series.
Thanks,
Andi
Hi Andi,
Thanks for the review and the notes.
I'll make sure to follow these guidelines for my future submissions.
Thanks,
Filippo
Re: [PATCH 2/2] i2c: amd8111: switch to devm_ functions
In reply to Filippo MuscheràQuoted 6 lines · Filippo Muscherà
Use
devm_kzalloc()to manage the memory allocation of the smbus structure anddevm_request_region()to manage the I/O port region.This simplifies the error handling paths in the probe function by removing manual cleanup and allows for the removal of the explicit cleanup in the remove function.
...
drivers/i2c/busses/i2c-amd8111.c static int amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id) · line 443
Quoted 6 lines
drivers/i2c/busses/i2c-amd8111.c +2
-4-if (!request_region (smbus->base, smbus->size, amd8111_driver.name)) { - error = -EBUSY ; - goto out_kfree; - } +if (!devm_request_region (&dev->dev, smbus->base, smbus->size, amd8111_driver.name)) +return -EBUSY ;
This is a PCI driver. Why not using the pcim_enable_device() with the respective pcim_*() call for the IO region?
I believe the driver misses pci_disable_device() as of the current implementation, switching to pcim_*() should address that as well.
...
drivers/i2c/busses/i2c-amd8111.c static void amd8111_remove(struct pci_dev *dev) · line 480
Quoted 7 lines
static void
amd8111_remove(struct pci_dev *dev)drivers/i2c/busses/i2c-amd8111.c +0
-2struct amd_smbus *smbus =pci_get_drvdata (dev);i2c_del_adapter (&smbus->adapter); -release_region (smbus->base, smbus->size); -kfree (smbus);
(Somewhere here I would expect pci_disable_device() to be called.)
Quoted 1 line
}
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 1/1 i2c: amd8111: Switch to pcim_enable_device() and pcim_request_region()
Following the conversion to managed devm_* APIs, update the driver to use the PCI-specific managed APIs.
Use pcim_enable_device() to properly enable the PCI device and pcim_request_region() to manage the I/O port region.
Switching to pcim_enable_device() also addresses the fact that pci_disable_device() was missing in the driver lifecycle, as the managed API now automatically handles the disablement when the driver unbinds.
--- drivers/i2c/busses/i2c-amd8111.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-amd8111.c +7 -2
@@ -427,6 +427,10 @@ static int amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id)if (!(pci_resource_flags (dev,0 ) &IORESOURCE_IO ))return -ENODEV ; + error =pcim_enable_device (dev); +if (error) +return error; + smbus =devm_kzalloc (&dev->dev,sizeof (struct amd_smbus ),GFP_KERNEL );if (!smbus)return -ENOMEM ;
@@ -439,8 +443,9 @@ static int amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id)if (error)return -ENODEV ; -if (!devm_request_region (&dev->dev, smbus->base, smbus->size, amd8111_driver.name)) -return -EBUSY ; + error =pcim_request_region (dev,0 , amd8111_driver.name); +if (error) +return error; smbus->adapter.owner =THIS_MODULE ; snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
Signature · 1 line
2.52.0
Re: [PATCH] i2c: amd8111: Switch to pcim_enable_device() and pcim_request_region()
Quoted 10 lines · Filippo Muscherà
Following the conversion to managed devm_* APIs, update the driver to use the PCI-specific managed APIs.
Use
pcim_enable_device()to properly enable the PCI device andpcim_request_region()to manage the I/O port region.Switching to
pcim_enable_device()also addresses the fact thatpci_disable_device()was missing in the driver lifecycle, as the managed API now automatically handles the disablement when the driver unbinds.
Looking at the code now I see the difference this patch may bring. I was under impression that there is pci_enable_device() already in the code. But it is not the case, which makes quite a different enumeration flow (it will write CMD register and touch some bits that might be sensitive). While the code looks okay and I can even
the change needs to be tested on real hardware before going in.
...
drivers/i2c/busses/i2c-amd8111.c static int amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id) · line 428
Quoted 2 lines
drivers/i2c/busses/i2c-amd8111.c +0
-0if (!(pci_resource_flags (dev,0 ) &IORESOURCE_IO ))return -ENODEV ;
While it seems now being unneeded, I would leave this check in place until somebody who knows the platform better can come up with a clear justification for its removal. It also sounds aligned with the above remark. It might be we can not do this patch at all.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH] i2c: amd8111: Switch to pcim_enable_device() and pcim_request_region()
Quoted 7 lines · Andy Shevchenko
Looking at the code now I see the difference this patch may bring. I was under impression that there is
pci_enable_device()already in the code. But it is not the case, which makes quite a different enumeration flow (it will write CMD register and touch some bits that might be sensitive). While the code looks okay and I can evenAcked-by Andy Shevchenko <[email protected]>the change needs to be tested on real hardware before going in.
Hi Andy,
Thanks for the review and the Acked-by.
Unfortunately I don't have access to an AMD8111 system to test if pcim_enable_device() causes any regressions.
I completely see the point you're making now. I was focusing purely on the API modernization and I didn't consider these legacy implications.
I leave it entirely up to you and the subsystem maintainers whether to queue this patch for testing or just drop it to avoid any risks.
Best regards,
Filippo
Andi Shyti
maintainerRe: [PATCH] i2c: amd8111: Switch to pcim_enable_device() and pcim_request_region()
In reply to Filippo MuscheràHi Filippo,
Quoted 6 lines · Filippo Muscherà
Following the conversion to managed devm_* APIs, update the driver to use the PCI-specific managed APIs.
Use
pcim_enable_device()to properly enable the PCI device andpcim_request_region()to manage the I/O port region.
Quoted 7 lines
Switching to
pcim_enable_device()also addresses the fact thatpci_disable_device()was missing in the driver lifecycle, as the managed API now automatically handles the disablement when the driver unbinds.Suggested-by Andy Shevchenko <[email protected]>Signed-off-by Filippo Muscherà <[email protected]>
Please, don't send a new patch as a in-reply-to to a different patch. I personally don't like patches sent as reply to a different thread, it makes my work as reviewer more difficult.
Said that, I would ask Jean to give an ack here.
Thanks,
Andi