Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934313AbbGGSxe (ORCPT ); Tue, 7 Jul 2015 14:53:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34377 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933415AbbGGSxU (ORCPT ); Tue, 7 Jul 2015 14:53:20 -0400 Subject: Re: [PATCH 1/1] infiniband: Remove redundant NULL check before kfree Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Content-Type: multipart/signed; boundary="Apple-Mail=_C4276367-BD6E-455B-8D4B-C2ED2F7E8F34"; protocol="application/pgp-signature"; micalg=pgp-sha512 X-Pgp-Agent: GPGMail 2.5 From: Doug Ledford In-Reply-To: <1435302547-40904-1-git-send-email-maninder1.s@samsung.com> Date: Tue, 7 Jul 2015 14:53:16 -0400 Cc: Sean Hefty , Or Gerlitz , David Miller , roland@purestorage.com, Matan Barak , Moni Shoua , jackm@dev.mellanox.co.il, Yishai Hadas , eranbe@mellanox.com, Ira Weiny , linux-rdma , linux-kernel , pankaj.m@samsung.com Message-Id: <6C49D012-DBBD-4AE8-B3A2-944B7823378E@redhat.com> References: <1435302547-40904-1-git-send-email-maninder1.s@samsung.com> To: Maninder Singh Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2943 Lines: 93 --Apple-Mail=_C4276367-BD6E-455B-8D4B-C2ED2F7E8F34 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jun 26, 2015, at 3:09 AM, Maninder Singh = wrote: >=20 > kfree(NULL) is safe and this check is probably not required >=20 > Signed-off-by: Maninder Singh > Reviewed-by: Akhilesh Kumar > --- > drivers/infiniband/hw/mlx4/main.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) >=20 > diff --git a/drivers/infiniband/hw/mlx4/main.c = b/drivers/infiniband/hw/mlx4/main.c > index 067a691..4e60b39 100644 > --- a/drivers/infiniband/hw/mlx4/main.c > +++ b/drivers/infiniband/hw/mlx4/main.c > @@ -2676,10 +2676,8 @@ static void do_slave_init(struct mlx4_ib_dev = *ibdev, int slave, int do_init) > dm[i] =3D kmalloc(sizeof (struct mlx4_ib_demux_work), = GFP_ATOMIC); > if (!dm[i]) { > pr_err("failed to allocate memory for tunneling = qp update work struct\n"); > - for (i =3D 0; i < dev->caps.num_ports; i++) { > - if (dm[i]) > - kfree(dm[i]); > - } > + for (i =3D 0; i < dev->caps.num_ports; i++) > + kfree(dm[i]); > goto out; > } > } > -- > 1.7.9.5 >=20 If you are going to change this, you might as well make it 100% correct: i=E2=80=94-; while (i >=3D 0) kfree(dm[i]); Then you don=E2=80=99t have to worry about whether kfree works on NULL, = every item you free will be guaranteed to be non-NULL. =E2=80=94 Doug Ledford GPG Key ID: 0E572FDD --Apple-Mail=_C4276367-BD6E-455B-8D4B-C2ED2F7E8F34 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAEBCgAGBQJVnCAcAAoJELgmozMOVy/d+EQQAKCvZI4vQ0JIuWUaZxtnt3Rx Hg1FPubWMrX+7kFd9QU/4hVqUMFb6DxyRkZnDq18dk1ksWtJyboA+edNKuVNYU0M f7aCrppkvdP2p0Rab4pTJ+dCDnoaWD9NUr007+rFNPm8SKcTIU2gUfV7xRrYN2BB C2k37Wsb3LQgTuTM0mfJcA++fvJ6Cm1kGKaNdIh6d35sWkbwaTniRGpDX/mGYmyv LwL3Rd0zIVNFPx505qG24bdqaiNOzWQ4MIdEYHIKk0dYy6tr68daIFI5VPCwAs/H 9ZtzUkW1dP2bMETeyXmIt0tSiP8YQy+aYrk59NfNOGgi7/CxGYeG8mgGYZRkqP9a N13MOEqwsvysUMu8Wr7o9dUfEYLIUGG74Pm+DERsWdK83Ng2UvREFBqjJFjaWHus undYC7LYkqwzM52d2d0iV3qgOBsfmhXffOhoebFfsih5XQbp2+fQBgGSwdtQ1Gea BMXCQkvffjom1ou6J0fCIpwVV67Q9LaQ280l9O8m6dSdy4G8DnAc7jEHkSTjy5c/ zxhgmt2hmqBYnQzyzPxCUiRBWvgA3ZB1lg+BpEhKmy6f5T6HejhPHwfHPz2gtyaz pz03uSjm9ZRe5bEnhlMrTYRqng1qT9Z46fh4w9KrEM2iREsTRnDbFFWKsdeRs4uS qGeGN92jdvc0kh9ZDv3p =hnAX -----END PGP SIGNATURE----- --Apple-Mail=_C4276367-BD6E-455B-8D4B-C2ED2F7E8F34-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/