ptp_ocp: set of small cleanups
cover ptp_ocp: set of small cleanups
The set of (independent) cleanups against ptp_ocp driver. Each patch has its own description, no need to repeat it here.
Andy Shevchenko (5):
ptp_ocp: use dev_err_probe()
ptp_ocp: use bits.h macros for all masks
ptp_ocp: drop duplicate NULL check in ptp_ocp_detach()
ptp_ocp: do not call pci_set_drvdata(pdev, NULL)
ptp_ocp: replace kzalloc(x*y) by kcalloc(y, x)
drivers/ptp/ptp_ocp.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/5 ptp_ocp: use dev_err_probe()
Simplify the error path in ->probe() and unify message format a bit by using dev_err_probe().
--- drivers/ptp/ptp_ocp.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/ptp/ptp_ocp.c +5 -8
@@ -3722,14 +3722,12 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)int err; devlink =devlink_alloc (&ptp_ocp_devlink_ops,sizeof (*bp), &pdev->dev); -if (!devlink) { -dev_err (&pdev->dev,"devlink_alloc failed\n" ); -return -ENOMEM ; - } +if (!devlink) +return dev_err_probe (&pdev->dev, -ENOMEM ,"devlink_alloc failed\n" ); err =pci_enable_device (pdev);if (err) { -dev_err (&pdev->dev,"pci_enable_device\n" ); +dev_err_probe (&pdev->dev, err,"pci_enable_device\n" ); goto out_free; }
@@ -3745,7 +3743,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)*/ err =pci_alloc_irq_vectors (pdev,1 ,17 ,PCI_IRQ_MSI |PCI_IRQ_MSIX );if (err <0 ) { -dev_err (&pdev->dev,"alloc_irq_vectors err: %d\n" , err); +dev_err_probe (&pdev->dev, err,"alloc_irq_vectors\n" ); goto out; } bp->n_irqs = err;
@@ -3757,8 +3755,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) bp->ptp =ptp_clock_register (&bp->ptp_info, &pdev->dev);if (IS_ERR (bp->ptp)) { - err =PTR_ERR (bp->ptp); -dev_err (&pdev->dev,"ptp_clock_register: %d\n" , err); + err =dev_err_probe (&pdev->dev,PTR_ERR (bp->ptp),"ptp_clock_register\n" ); bp->ptp =NULL ; goto out; }
Signature · 1 line
2.35.1
Re: [PATCH net-next v1 1/5] ptp_ocp: use dev_err_probe()
Quoted 4 lines · Andy Shevchenko
Simplify the error path in ->probe() and unify message format a bit by using
dev_err_probe().Signed-off-by Andy Shevchenko <[email protected]>
LGTM
Quoted 45 lines
--- drivers/ptp/ptp_ocp.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)drivers/ptp/ptp_ocp.c +5
-8@@ -3722,14 +3722,12 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)int err; devlink =devlink_alloc (&ptp_ocp_devlink_ops,sizeof (*bp), &pdev->dev); -if (!devlink) { -dev_err (&pdev->dev,"devlink_alloc failed\n" ); -return -ENOMEM ; - } +if (!devlink) +return dev_err_probe (&pdev->dev, -ENOMEM ,"devlink_alloc failed\n" ); err =pci_enable_device (pdev);if (err) { -dev_err (&pdev->dev,"pci_enable_device\n" ); +dev_err_probe (&pdev->dev, err,"pci_enable_device\n" ); goto out_free; }@@ -3745,7 +3743,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)*/ err =pci_alloc_irq_vectors (pdev,1 ,17 ,PCI_IRQ_MSI |PCI_IRQ_MSIX );if (err <0 ) { -dev_err (&pdev->dev,"alloc_irq_vectors err: %d\n" , err); +dev_err_probe (&pdev->dev, err,"alloc_irq_vectors\n" ); goto out; } bp->n_irqs = err;@@ -3757,8 +3755,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) bp->ptp =ptp_clock_register (&bp->ptp_info, &pdev->dev);if (IS_ERR (bp->ptp)) { - err =PTR_ERR (bp->ptp); -dev_err (&pdev->dev,"ptp_clock_register: %d\n" , err); + err =dev_err_probe (&pdev->dev,PTR_ERR (bp->ptp),"ptp_clock_register\n" ); bp->ptp =NULL ; goto out; }
Re: [PATCH net-next v1 1/5] ptp_ocp: use dev_err_probe()
In reply to Andy ShevchenkoQuoted 2 lines · Andy Shevchenko
Simplify the error path in ->probe() and unify message format a bit by using
dev_err_probe().
Line length.
Signature · 1 line
Jonathan
Jakub Kicinski
maintainerRe: [PATCH net-next v1 1/5] ptp_ocp: use dev_err_probe()
In reply to Andy ShevchenkoQuoted 2 lines · On Wed, 8 Jun 2022 15:03:54 +0300 Andy Shevchenko wrote:
Simplify the error path in ->probe() and unify message format a bit by using
dev_err_probe().
Let's not do this. I get that using dev_err_probe() even without possibility of -EPROBE_DEFER is acceptable, but converting existing drivers is too much IMO. Acceptable < best practice.
Re: [PATCH net-next v1 1/5] ptp_ocp: use dev_err_probe()
Quoted 7 lines · Jakub Kicinski
Quoted 2 lines · On Wed, 8 Jun 2022 15:03:54 +0300 Andy Shevchenko wrote:
Simplify the error path in ->probe() and unify message format a bit by using
dev_err_probe().Let's not do this. I get that using
dev_err_probe()even without possibility of -EPROBE_DEFER is acceptable, but converting existing drivers is too much IMO. Acceptable < best practice.
Noted.
I have just checked that if you drop this patch the rest will be still applicable. If you have no objections, can you apply patches 2-5 then?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jakub Kicinski
maintainerRe: [PATCH net-next v1 1/5] ptp_ocp: use dev_err_probe()
Quoted 2 lines · On Fri, 10 Jun 2022 14:09:24 +0300 Andy Shevchenko wrote:
I have just checked that if you drop this patch the rest will be still applicable. If you have no objections, can you apply patches 2-5 then?
It's tradition in netdev to ask people to repost. But looks completely safe for me to drop patch 1, so applied 2-5. Don't tell anyone I did this.
Re: [PATCH net-next v1 1/5] ptp_ocp: use dev_err_probe()
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 10 Jun 2022 14:09:24 +0300 Andy Shevchenko wrote:
I have just checked that if you drop this patch the rest will be still applicable. If you have no objections, can you apply patches 2-5 then?
It's tradition in netdev to ask people to repost. But looks completely safe for me to drop patch 1, so applied 2-5. Don't tell anyone I did this.
I see what you did there. :)
Signature · 1 line
Jonathan
Re: [PATCH net-next v1 1/5] ptp_ocp: use dev_err_probe()
In reply to Jakub KicinskiQuoted 7 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 10 Jun 2022 14:09:24 +0300 Andy Shevchenko wrote:
I have just checked that if you drop this patch the rest will be still applicable. If you have no objections, can you apply patches 2-5 then?
It's tradition in netdev to ask people to repost. But looks completely safe for me to drop patch 1, so applied 2-5.
Thanks!
Quoted 1 line
Don't tell anyone I did this.
Tschhh!
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 2/5 ptp_ocp: use bits.h macros for all masks
In reply to Andy ShevchenkoCurrently we are using BIT(), but GENMASK(). Make use of the latter one as well (far less error-prone, far more concise).
--- drivers/ptp/ptp_ocp.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/ptp/ptp_ocp.c +7 -6
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2020 Facebook */ +#include <linux/bits.h> #include <linux/err.h> #include <linux/kernel.h> #include <linux/module.h>
@@ -88,10 +89,10 @@ struct tod_reg {#define TOD_CTRL_DISABLE_FMT_A BIT(17)#define TOD_CTRL_DISABLE_FMT_B BIT(16)#define TOD_CTRL_ENABLE BIT(0) -#define TOD_CTRL_GNSS_MASK ((1U << 4) - 1) +#define TOD_CTRL_GNSS_MASK GENMASK(3, 0)#define TOD_CTRL_GNSS_SHIFT 24 -#define TOD_STATUS_UTC_MASK 0xff +#define TOD_STATUS_UTC_MASK GENMASK(7, 0)#define TOD_STATUS_UTC_VALID BIT(8)#define TOD_STATUS_LEAP_ANNOUNCE BIT(12)#define TOD_STATUS_LEAP_VALID BIT(16)
@@ -205,7 +206,7 @@ struct frequency_reg {#define FREQ_STATUS_VALID BIT(31)#define FREQ_STATUS_ERROR BIT(30)#define FREQ_STATUS_OVERRUN BIT(29) -#define FREQ_STATUS_MASK (BIT(24) - 1) +#define FREQ_STATUS_MASK GENMASK(23, 0)struct ptp_ocp_flash_info {const char *name;
@@ -674,9 +675,9 @@ static const struct ocp_selector ptp_ocp_clock[] = { { } }; +#define SMA_DISABLE BIT(16)#define SMA_ENABLE BIT(15) -#define SMA_SELECT_MASK ((1U << 15) - 1) -#define SMA_DISABLE 0x10000 +#define SMA_SELECT_MASK GENMASK(14, 0)static const struct ocp_selector ptp_ocp_sma_in[] = { { .name ="10Mhz" , .value =0x0000 },
@@ -3440,7 +3441,7 @@ ptp_ocp_tod_status_show(struct seq_file *s, void *data) val =ioread32 (&bp->tod->utc_status);seq_printf (s,"UTC status register: 0x%08X\n" , val); -seq_printf (s,"UTC offset: %d valid:%d\n" , +seq_printf (s,"UTC offset: %ld valid:%d\n" , val &TOD_STATUS_UTC_MASK , val &TOD_STATUS_UTC_VALID ?1 :0 ); seq_printf(s, "Leap second info valid:%d, Leap second announce %d\n", val & TOD_STATUS_LEAP_VALID ? 1 : 0,
Signature · 1 line
2.35.1
Re: [PATCH v1 net-next 2/5] ptp_ocp: use bits.h macros for all masks
Quoted 4 lines · Andy Shevchenko
Currently we are using
BIT(), butGENMASK(). Make use of the latter one as well (far less error-prone, far more concise).Signed-off-by Andy Shevchenko <[email protected]>
LGTM
Quoted 59 lines
--- drivers/ptp/ptp_ocp.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/ptp/ptp_ocp.c +7
-6@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2020 Facebook */ +#include <linux/bits.h> #include <linux/err.h> #include <linux/kernel.h> #include <linux/module.h> @@ -88,10 +89,10 @@ struct tod_reg {#define TOD_CTRL_DISABLE_FMT_A BIT(17)#define TOD_CTRL_DISABLE_FMT_B BIT(16)#define TOD_CTRL_ENABLE BIT(0) -#define TOD_CTRL_GNSS_MASK ((1U << 4) - 1) +#define TOD_CTRL_GNSS_MASK GENMASK(3, 0)#define TOD_CTRL_GNSS_SHIFT 24 -#define TOD_STATUS_UTC_MASK 0xff +#define TOD_STATUS_UTC_MASK GENMASK(7, 0)#define TOD_STATUS_UTC_VALID BIT(8)#define TOD_STATUS_LEAP_ANNOUNCE BIT(12)#define TOD_STATUS_LEAP_VALID BIT(16)@@ -205,7 +206,7 @@ struct frequency_reg {#define FREQ_STATUS_VALID BIT(31)#define FREQ_STATUS_ERROR BIT(30)#define FREQ_STATUS_OVERRUN BIT(29) -#define FREQ_STATUS_MASK (BIT(24) - 1) +#define FREQ_STATUS_MASK GENMASK(23, 0)struct ptp_ocp_flash_info {const char *name;@@ -674,9 +675,9 @@ static const struct ocp_selector ptp_ocp_clock[] = { { } }; +#define SMA_DISABLE BIT(16)#define SMA_ENABLE BIT(15) -#define SMA_SELECT_MASK ((1U << 15) - 1) -#define SMA_DISABLE 0x10000 +#define SMA_SELECT_MASK GENMASK(14, 0)static const struct ocp_selector ptp_ocp_sma_in[] = { { .name ="10Mhz" , .value =0x0000 },@@ -3440,7 +3441,7 @@ ptp_ocp_tod_status_show(struct seq_file *s, void *data) val =ioread32 (&bp->tod->utc_status);seq_printf (s,"UTC status register: 0x%08X\n" , val); -seq_printf (s,"UTC offset: %d valid:%d\n" , +seq_printf (s,"UTC offset: %ld valid:%d\n" , val &TOD_STATUS_UTC_MASK , val &TOD_STATUS_UTC_VALID ?1 :0 ); seq_printf(s, "Leap second info valid:%d, Leap second announce %d\n", val & TOD_STATUS_LEAP_VALID ? 1 : 0,
PATCH 3/5 ptp_ocp: drop duplicate NULL check in ptp_ocp_detach()
In reply to Andy ShevchenkoSince platform_device_unregister() is NULL-aware, we don't need to duplicate this check. Remove it and fold the rest of the code.
--- drivers/ptp/ptp_ocp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/ptp/ptp_ocp.c +2 -4
@@ -3701,10 +3701,8 @@ ptp_ocp_detach(struct ptp_ocp *bp)serial8250_unregister_port (bp->mac_port);if (bp->nmea_port !=-1 )serial8250_unregister_port (bp->nmea_port); -if (bp->spi_flash) -platform_device_unregister (bp->spi_flash); -if (bp->i2c_ctrl) -platform_device_unregister (bp->i2c_ctrl); +platform_device_unregister (bp->spi_flash); +platform_device_unregister (bp->i2c_ctrl);if (bp->i2c_clk)clk_hw_unregister_fixed_rate (bp->i2c_clk);if (bp->n_irqs)
Signature · 1 line
2.35.1
Re: [PATCH v1 net-next 3/5] ptp_ocp: drop duplicate NULL check in ptp_ocp_detach()
Quoted 4 lines · Andy Shevchenko
Since
platform_device_unregister()is NULL-aware, we don't need to duplicate this check. Remove it and fold the rest of the code.Signed-off-by Andy Shevchenko <[email protected]>
Quoted 21 lines
--- drivers/ptp/ptp_ocp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/ptp/ptp_ocp.c +2
-4@@ -3701,10 +3701,8 @@ ptp_ocp_detach(struct ptp_ocp *bp)serial8250_unregister_port (bp->mac_port);if (bp->nmea_port !=-1 )serial8250_unregister_port (bp->nmea_port); -if (bp->spi_flash) -platform_device_unregister (bp->spi_flash); -if (bp->i2c_ctrl) -platform_device_unregister (bp->i2c_ctrl); +platform_device_unregister (bp->spi_flash); +platform_device_unregister (bp->i2c_ctrl);if (bp->i2c_clk)clk_hw_unregister_fixed_rate (bp->i2c_clk);if (bp->n_irqs)
PATCH 4/5 ptp_ocp: do not call pci_set_drvdata(pdev, NULL)
In reply to Andy ShevchenkoCleaning up driver data is actually already handled by driver core, so there is no need to do it manually.
--- drivers/ptp/ptp_ocp.c | 2 -- 1 file changed, 2 deletions(-)
drivers/ptp/ptp_ocp.c +0 -2
@@ -3769,7 +3769,6 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) out:ptp_ocp_detach (bp); -pci_set_drvdata (pdev,NULL ); out_disable:pci_disable_device (pdev); out_free:
@@ -3785,7 +3784,6 @@ ptp_ocp_remove(struct pci_dev *pdev)devlink_unregister (devlink);ptp_ocp_detach (bp); -pci_set_drvdata (pdev,NULL );pci_disable_device (pdev);devlink_free (devlink);
Signature · 1 line
2.35.1
Re: [PATCH v1 net-next 4/5] ptp_ocp: do not call pci_set_drvdata(pdev, NULL)
Quoted 2 lines · Andy Shevchenko
Cleaning up driver data is actually already handled by driver core, so there is no need to do it manually.
I found a couple of places with exactly the same code in error path. For example Marvell's OcteonX drivers in crypto and net subsystems. Should we fix them too?
Quoted 1 line
Signed-off-by Andy Shevchenko <[email protected]>
Overall looks good.
Quoted 24 lines
--- drivers/ptp/ptp_ocp.c | 2 -- 1 file changed, 2 deletions(-)drivers/ptp/ptp_ocp.c +0
-2@@ -3769,7 +3769,6 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) out:ptp_ocp_detach (bp); -pci_set_drvdata (pdev,NULL ); out_disable:pci_disable_device (pdev); out_free:@@ -3785,7 +3784,6 @@ ptp_ocp_remove(struct pci_dev *pdev)devlink_unregister (devlink);ptp_ocp_detach (bp); -pci_set_drvdata (pdev,NULL );pci_disable_device (pdev);devlink_free (devlink);
Re: [PATCH v1 net-next 4/5] ptp_ocp: do not call pci_set_drvdata(pdev, NULL)
Quoted 8 lines · Vadim Fedorenko
Quoted 2 lines · Andy Shevchenko
Cleaning up driver data is actually already handled by driver core, so there is no need to do it manually.
I found a couple of places with exactly the same code in error path. For example Marvell's OcteonX drivers in crypto and net subsystems. Should we fix them too?
I believe there are even more, but feel free to fix them, they are not my POI.
...
Quoted 3 lines
Overall looks good.
Acked-by Vadim Fedorenko <[email protected]>
Thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 5/5 ptp_ocp: replace kzalloc(x*y) by kcalloc(y, x)
In reply to Andy ShevchenkoWhile here it may be no difference, the kcalloc() has some checks against overflow and it's logically correct to call it for an array.
--- drivers/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +1 -1
@@ -2155,7 +2155,7 @@ ptp_ocp_fb_set_pins(struct ptp_ocp *bp)struct ptp_pin_desc *config;int i; - config =kzalloc (sizeof (*config) *4 ,GFP_KERNEL ); + config =kcalloc (4 ,sizeof (*config),GFP_KERNEL );if (!config)return -ENOMEM ;
Signature · 1 line
2.35.1
Re: [PATCH v1 net-next 5/5] ptp_ocp: replace kzalloc(x*y) by kcalloc(y, x)
Quoted 4 lines · Andy Shevchenko
While here it may be no difference, the
kcalloc()has some checks against overflow and it's logically correct to call it for an array.Signed-off-by Andy Shevchenko <[email protected]>
Quoted 17 lines
--- drivers/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/ptp/ptp_ocp.c +1
-1@@ -2155,7 +2155,7 @@ ptp_ocp_fb_set_pins(struct ptp_ocp *bp)struct ptp_pin_desc *config;int i; - config =kzalloc (sizeof (*config) *4 ,GFP_KERNEL ); + config =kcalloc (4 ,sizeof (*config),GFP_KERNEL );if (!config)return -ENOMEM ;