loongson_dwmac_probe() contains a loop which doesn't have an effect,
because it tries to call pcim_iomap_regions() with the same parameters
several times. The break statement at the loop's end furthermore ensures
that the loop only runs once anyways.
Remove the surplus loop.
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
index 73a6715a93e6..e3cacd085b3f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
@@ -554,14 +554,9 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
pci_set_master(pdev);
/* Get the base address of device */
- for (i = 0; i < PCI_STD_NUM_BARS; i++) {
- if (pci_resource_len(pdev, i) == 0)
- continue;
- ret = pcim_iomap_regions(pdev, BIT(0), DRIVER_NAME);
- if (ret)
- goto err_disable_device;
- break;
- }
+ ret = pcim_iomap_regions(pdev, BIT(0), DRIVER_NAME);
+ if (ret)
+ goto err_disable_device;
memset(&res, 0, sizeof(res));
res.addr = pcim_iomap_table(pdev)[0];
--
2.48.1
On Mon, Feb 24, 2025 at 9:53 PM Philipp Stanner <phasta@kernel.org> wrote:
>
> loongson_dwmac_probe() contains a loop which doesn't have an effect,
> because it tries to call pcim_iomap_regions() with the same parameters
> several times. The break statement at the loop's end furthermore ensures
> that the loop only runs once anyways.
>
> Remove the surplus loop.
>
> Signed-off-by: Philipp Stanner <phasta@kernel.org>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> index 73a6715a93e6..e3cacd085b3f 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> @@ -554,14 +554,9 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
> pci_set_master(pdev);
>
> /* Get the base address of device */
> - for (i = 0; i < PCI_STD_NUM_BARS; i++) {
> - if (pci_resource_len(pdev, i) == 0)
> - continue;
> - ret = pcim_iomap_regions(pdev, BIT(0), DRIVER_NAME);
> - if (ret)
> - goto err_disable_device;
> - break;
> - }
> + ret = pcim_iomap_regions(pdev, BIT(0), DRIVER_NAME);
> + if (ret)
> + goto err_disable_device;
>
> memset(&res, 0, sizeof(res));
> res.addr = pcim_iomap_table(pdev)[0];
> --
> 2.48.1
>
在 2/24/25 9:53 PM, Philipp Stanner 写道:
> loongson_dwmac_probe() contains a loop which doesn't have an effect,
> because it tries to call pcim_iomap_regions() with the same parameters
> several times. The break statement at the loop's end furthermore ensures
> that the loop only runs once anyways.
>
> Remove the surplus loop.
>
> Signed-off-by: Philipp Stanner <phasta@kernel.org>
It seems that the fix-tag has been forgotten, next two patches as well.
Reviewed-by: Yanteng Si <si.yanteng@linux.dev>
Thanks,
Yanteng
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> index 73a6715a93e6..e3cacd085b3f 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> @@ -554,14 +554,9 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
> pci_set_master(pdev);
>
> /* Get the base address of device */
> - for (i = 0; i < PCI_STD_NUM_BARS; i++) {
> - if (pci_resource_len(pdev, i) == 0)
> - continue;
> - ret = pcim_iomap_regions(pdev, BIT(0), DRIVER_NAME);
> - if (ret)
> - goto err_disable_device;
> - break;
> - }
> + ret = pcim_iomap_regions(pdev, BIT(0), DRIVER_NAME);
> + if (ret)
> + goto err_disable_device;
>
> memset(&res, 0, sizeof(res));
> res.addr = pcim_iomap_table(pdev)[0];
On Tue, 2025-02-25 at 17:06 +0800, Yanteng Si wrote:
>
> 在 2/24/25 9:53 PM, Philipp Stanner 写道:
> > loongson_dwmac_probe() contains a loop which doesn't have an
> > effect,
> > because it tries to call pcim_iomap_regions() with the same
> > parameters
> > several times. The break statement at the loop's end furthermore
> > ensures
> > that the loop only runs once anyways.
> >
> > Remove the surplus loop.
> >
> > Signed-off-by: Philipp Stanner <phasta@kernel.org>
>
> It seems that the fix-tag has been forgotten, next two patches as
> well.
Not forgotten, I just think that patches 2-4 are code improvements, not
bug fixes.
The issue in patch 1 would cause actual misbehavior (a useless debug
information print in case of a resource collision), whereas 2-4 are
just ugly code, but not actual bugs: the loop always just runs once;
and unmapping the PCI resources manually is valid, but obviously
unnecessary.
Agreed?
P.
>
>
> Reviewed-by: Yanteng Si <si.yanteng@linux.dev>
>
> Thanks,
> Yanteng
>
> > ---
> > drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 +++----
> > ----
> > 1 file changed, 3 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> > b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> > index 73a6715a93e6..e3cacd085b3f 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c
> > @@ -554,14 +554,9 @@ static int loongson_dwmac_probe(struct pci_dev
> > *pdev, const struct pci_device_id
> > pci_set_master(pdev);
> >
> > /* Get the base address of device */
> > - for (i = 0; i < PCI_STD_NUM_BARS; i++) {
> > - if (pci_resource_len(pdev, i) == 0)
> > - continue;
> > - ret = pcim_iomap_regions(pdev, BIT(0),
> > DRIVER_NAME);
> > - if (ret)
> > - goto err_disable_device;
> > - break;
> > - }
> > + ret = pcim_iomap_regions(pdev, BIT(0), DRIVER_NAME);
> > + if (ret)
> > + goto err_disable_device;
> >
> > memset(&res, 0, sizeof(res));
> > res.addr = pcim_iomap_table(pdev)[0];
在 2/25/25 5:15 PM, Philipp Stanner 写道: > On Tue, 2025-02-25 at 17:06 +0800, Yanteng Si wrote: >> 在 2/24/25 9:53 PM, Philipp Stanner 写道: >>> loongson_dwmac_probe() contains a loop which doesn't have an >>> effect, >>> because it tries to call pcim_iomap_regions() with the same >>> parameters >>> several times. The break statement at the loop's end furthermore >>> ensures >>> that the loop only runs once anyways. >>> >>> Remove the surplus loop. >>> >>> Signed-off-by: Philipp Stanner <phasta@kernel.org> >> It seems that the fix-tag has been forgotten, next two patches as >> well. > Not forgotten, I just think that patches 2-4 are code improvements, not > bug fixes. > > The issue in patch 1 would cause actual misbehavior (a useless debug > information print in case of a resource collision), whereas 2-4 are > just ugly code, but not actual bugs: the loop always just runs once; > and unmapping the PCI resources manually is valid, but obviously > unnecessary. > > Agreed? You bet! Thanks, Yanteng >
On Mon, Feb 24, 2025 at 02:53:20PM +0100, Philipp Stanner wrote:
> loongson_dwmac_probe() contains a loop which doesn't have an effect,
> because it tries to call pcim_iomap_regions() with the same parameters
> several times. The break statement at the loop's end furthermore ensures
> that the loop only runs once anyways.
>
> Remove the surplus loop.
>
> Signed-off-by: Philipp Stanner <phasta@kernel.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
© 2016 - 2025 Red Hat, Inc.