Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751789AbbGHVzI (ORCPT ); Wed, 8 Jul 2015 17:55:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60737 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751007AbbGHVzC (ORCPT ); Wed, 8 Jul 2015 17:55:02 -0400 Message-ID: <559D9C30.5090203@redhat.com> Date: Wed, 08 Jul 2015 17:54:56 -0400 From: Doug Ledford Organization: Red Hat, Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Maninder Singh , sean.hefty@intel.com, hal.rosenstock@gmail.com, ogerlitz@mellanox.com, davem@davemloft.net, roland@purestorage.com, matanb@mellanox.com, monis@mellanox.com, jackm@dev.mellanox.co.il, yishaih@mellanox.com, eranbe@mellanox.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org CC: pankaj.m@samsung.com Subject: Re: [PATCH v2] infiniband: free only allocated items References: <1436328815-28072-1-git-send-email-maninder1.s@samsung.com> In-Reply-To: <1436328815-28072-1-git-send-email-maninder1.s@samsung.com> OpenPGP: id=AE6B1BDA122B23B4265B1274B826A3330E572FDD; url=pgp.mit.edu Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="QFWXRhnOqiBCw4VG1lKfApJ5B76fgrts0" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3482 Lines: 98 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --QFWXRhnOqiBCw4VG1lKfApJ5B76fgrts0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 07/08/2015 12:13 AM, Maninder Singh wrote: > o If allocation of dm fails, no need to free it. > o Free only allocated items. I've taken the patch, but I reworked your commit message. The v1 version of the patch had a more correct commit message, but it could have used a little rework as well. This is what I entered in the commit message: IB/mlx4: Optimize freeing of items on error unwind On failure, we loop through all possible pointers and test them before calling kfree. But really, why even attempt to free items we didn't allocate when we can easily loop through exactly and only the devices for which the original memory allocation succeeded and free just those. Signed-off-by: Maninder Singh Signed-off-by: Doug Ledford >=20 > Signed-off-by: Maninder Singh > --- > drivers/infiniband/hw/mlx4/main.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) >=20 > diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/= mlx4/main.c > index 067a691..253498f 100644 > --- a/drivers/infiniband/hw/mlx4/main.c > +++ b/drivers/infiniband/hw/mlx4/main.c > @@ -2669,17 +2669,15 @@ static void do_slave_init(struct mlx4_ib_dev *i= bdev, int slave, int do_init) > dm =3D kcalloc(ports, sizeof(*dm), GFP_ATOMIC); > if (!dm) { > pr_err("failed to allocate memory for tunneling qp update\n"); > - goto out; > + return; > } > =20 > for (i =3D 0; i < ports; i++) { > 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 stru= ct\n"); > - for (i =3D 0; i < dev->caps.num_ports; i++) { > - if (dm[i]) > - kfree(dm[i]); > - } > + while (--i >=3D 0) > + kfree(dm[i]); > goto out; > } > } >=20 --=20 Doug Ledford GPG KeyID: 0E572FDD --QFWXRhnOqiBCw4VG1lKfApJ5B76fgrts0 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJVnZwwAAoJELgmozMOVy/dwPEQALIV4qotUuCIeW2eyWf8tLaM 95oH2JXe9IDXY9JJeYOTPM8HyG1AL58YXVq9kUPHhk/v6BqgAQssvYf0NatMGoCl eijG7C74SXWLqcXObYm/UKaWZSdlIGouhI2s49JKAKMdWnPbax+RdaWATKfGbk6d O0Nry6gtmB+sfOPNepcUlki1sxE35y72mt4gtJLVmq0h0IYGnhiyVimqVeyYHyZX YcEIIahhoRwCfLI6PZqXNVWYQwewuH7ZAKA5xMhfOtaszRHfEih9pgiulTjCK/gS QckNzU24VjoOrad0NqSw3WTJtmo51cRFzOAKmFDtQdRmw/n7HONanbRfjBQ6rsOE uJjCou3UjWTYY9MW11+eYrV58yq2CjqqUYbDk+Er5tabxa5pdUkGFmQYZAel3T07 Zkw6kos+WTMZY3ZMtUbiubVmhMO3NU+kGRyECm2LsoytyItP4NbhqsRo5EwlN+xW nsOL9HR9XGI3rGkSH4iqulQRn2b1Na2iwVCdBjWkh7t38qea+5zNi0KJRs3ocPkq gFZhXRatsrfvQpf7pBYhG542h795wh0sB0V59G1uyOtX+MooBmqVwYuprCxzYjZJ TXrgQXLJnEkZMuHh8ln53g/Ak0s7QWkTjzu3rcBVlm2AR3ydniKPrLqP5gFOnglI jY7BwUzvCklLnwE5D2/W =cVX7 -----END PGP SIGNATURE----- --QFWXRhnOqiBCw4VG1lKfApJ5B76fgrts0-- -- 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/