Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1248030

Re: [PATCH] usnic: corretly check failed allocation

From "Dave Goodell (dgoodell)" <dgoodell@cisco.com>
Newsgroups linux.kernel
Subject Re: [PATCH] usnic: corretly check failed allocation
Date 2015-10-15 19:30 +0200
Message-ID <qjUvM-4Ij-15@gated-at.bofh.it> (permalink)
References <qjTzK-3md-61@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Oct 15, 2015, at 11:27 AM, Insu Yun <wuninsu@gmail.com> wrote:
> 
> Since ib_alloc_device returns allocated memory address, not error, 
> it should be checked as IS_NULL, not IS_ERR_OR_NULL.
> 
> Signed-off-by: Insu Yun <wuninsu@gmail.com>
> ---
> drivers/infiniband/hw/usnic/usnic_ib_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

There's a typo in the subject ("corretly"-->"correctly").

Out of curiosity, what led you to spot this?  General code inspection or did this come out of some tool?

> diff --git a/drivers/infiniband/hw/usnic/usnic_ib_main.c b/drivers/infiniband/hw/usnic/usnic_ib_main.c
> index 34c49b8..7c5f602 100644
> --- a/drivers/infiniband/hw/usnic/usnic_ib_main.c
> +++ b/drivers/infiniband/hw/usnic/usnic_ib_main.c
> @@ -328,14 +328,14 @@ static void *usnic_ib_device_add(struct pci_dev *dev)
> 	netdev = pci_get_drvdata(dev);
> 
> 	us_ibdev = (struct usnic_ib_dev *)ib_alloc_device(sizeof(*us_ibdev));
> -	if (IS_ERR_OR_NULL(us_ibdev)) {
> +	if (!us_ibdev) {
> 		usnic_err("Device %s context alloc failed\n",
> 				netdev_name(pci_get_drvdata(dev)));
> 		return ERR_PTR(us_ibdev ? PTR_ERR(us_ibdev) : -EFAULT);

I think this can become:

return ERR_PTR(-EFAULT);

> 	}
> 
> 	us_ibdev->ufdev = usnic_fwd_dev_alloc(dev);
> -	if (IS_ERR_OR_NULL(us_ibdev->ufdev)) {
> +	if (!us_ibdev->ufdev) {
> 		usnic_err("Failed to alloc ufdev for %s with err %ld\n",
> 				pci_name(dev), PTR_ERR(us_ibdev->ufdev));

This PTR_ERR and message make less sense now.

-Dave

--
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/

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] usnic: corretly check failed allocation Insu Yun <wuninsu@gmail.com> - 2015-10-15 18:30 +0200
  Re: [PATCH] usnic: corretly check failed allocation "Dave Goodell (dgoodell)" <dgoodell@cisco.com> - 2015-10-15 19:30 +0200
    Re: [PATCH] usnic: corretly check failed allocation Dave Goodell <dgoodell@cisco.com> - 2015-10-15 23:00 +0200

csiph-web