Message ID | 546CE09B.9090101@users.sourceforge.net (mailing list archive) |
---|---|
State | Rejected |
Headers | show |
> From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 19 Nov 2014 19:19:21 +0100 > > The functions kfree() and pci_dev_put() test whether their argument is NULL > and then return immediately. Thus the test around the call is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/infiniband/hw/mlx4/main.c | 3 +-- > drivers/infiniband/hw/mthca/mthca_reset.c | 3 +-- > 2 files changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c > index 8b72cf3..50dee1a 100644 > --- a/drivers/infiniband/hw/mlx4/main.c > +++ b/drivers/infiniband/hw/mlx4/main.c > @@ -2512,8 +2512,7 @@ static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init) > if (!dm[i]) { > pr_err("failed to allocate memory for tunneling qp update work struct\n"); > for (i = 0; i < dev->caps.num_ports; i++) { > - if (dm[i]) > - kfree(dm[i]); > + kfree(dm[i]); > } > goto out; > } > diff --git a/drivers/infiniband/hw/mthca/mthca_reset.c b/drivers/infiniband/hw/mthca/mthca_reset.c > index 74c6a94..c521654 100644 > --- a/drivers/infiniband/hw/mthca/mthca_reset.c > +++ b/drivers/infiniband/hw/mthca/mthca_reset.c > @@ -279,8 +279,7 @@ good: > } > > out: > - if (bridge) > - pci_dev_put(bridge); > + pci_dev_put(bridge); > kfree(bridge_header); > kfree(hca_header); > > More software developers became interested in similar source code improvements. infiniband: Remove redundant NULL check before kfree https://lkml.org/lkml/2015/6/26/45 https://www.mail-archive.com/linux-kernel%40vger.kernel.org/msg919966.html Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 23 Jul 2016 12:50:12 +0200
Further update suggestions were taken into account
after a patch was applied from static source code analysis.
Markus Elfring (3):
Delete an unnecessary check before the function call "pci_dev_put"
Less function calls after error detection
Delete unnecessary variable initialisations
drivers/infiniband/hw/mthca/mthca_reset.c | 48 +++++++++++++++----------------
1 file changed, 23 insertions(+), 25 deletions(-)
On Sat, 2016-07-23 at 12:55 +0200, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 23 Jul 2016 12:50:12 +0200 > > Further update suggestions were taken into account > after a patch was applied from static source code analysis. > > Markus Elfring (3): > Delete an unnecessary check before the function call "pci_dev_put" > Less function calls after error detection > Delete unnecessary variable initialisations > > drivers/infiniband/hw/mthca/mthca_reset.c | 48 +++++++++++++++---- > ------------ > 1 file changed, 23 insertions(+), 25 deletions(-) > I applied 1 and 2, but skipped 3. My memory from long ago is that those variables didn't used to have initializers, but the compiler complained, so the initialization was added at some point. This is a dead driver, only around for the few systems out there using out dated hardware. I don't want to change this and then have to revert it because the old warnings came back, so I just dropped that patch.
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index 8b72cf3..50dee1a 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -2512,8 +2512,7 @@ static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init) if (!dm[i]) { pr_err("failed to allocate memory for tunneling qp update work struct\n"); for (i = 0; i < dev->caps.num_ports; i++) { - if (dm[i]) - kfree(dm[i]); + kfree(dm[i]); } goto out; } diff --git a/drivers/infiniband/hw/mthca/mthca_reset.c b/drivers/infiniband/hw/mthca/mthca_reset.c index 74c6a94..c521654 100644 --- a/drivers/infiniband/hw/mthca/mthca_reset.c +++ b/drivers/infiniband/hw/mthca/mthca_reset.c @@ -279,8 +279,7 @@ good: } out: - if (bridge) - pci_dev_put(bridge); + pci_dev_put(bridge); kfree(bridge_header); kfree(hca_header);