mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usnic: corretly check failed allocation
@ 2015-10-15 16:27 Insu Yun
  2015-10-15 17:17 ` Dave Goodell (dgoodell)
  0 siblings, 1 reply; 3+ messages in thread
From: Insu Yun @ 2015-10-15 16:27 UTC (permalink / raw)
  To: umalhi, dledford, sean.hefty, hal.rosenstock, linux-rdma, linux-kernel
  Cc: taesoo, yeongjin.jang, insu, Insu Yun

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(-)

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);
 	}
 
 	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));
 		goto err_dealloc;
-- 
1.9.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usnic: corretly check failed allocation
  2015-10-15 16:27 [PATCH] usnic: corretly check failed allocation Insu Yun
@ 2015-10-15 17:17 ` Dave Goodell (dgoodell)
       [not found]   ` <CAGoFzNdD+b1co+6zsEo94KP3APLk353fwOQkgdMjh01UOG-9Ng@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Goodell (dgoodell) @ 2015-10-15 17:17 UTC (permalink / raw)
  To: Insu Yun
  Cc: umalhi, dledford, sean.hefty, hal.rosenstock, linux-rdma,
	linux-kernel, taesoo, yeongjin.jang, insu

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usnic: corretly check failed allocation
       [not found]   ` <CAGoFzNdD+b1co+6zsEo94KP3APLk353fwOQkgdMjh01UOG-9Ng@mail.gmail.com>
@ 2015-10-15 20:52     ` Dave Goodell
  0 siblings, 0 replies; 3+ messages in thread
From: Dave Goodell @ 2015-10-15 20:52 UTC (permalink / raw)
  To: Insu Yun
  Cc: umalhi, dledford, sean.hefty, hal.rosenstock, linux-rdma,
	linux-kernel, taesoo, yeongjin.jang, insu

On Thu, Oct 15, 2015 at 01:41:06PM -0400, Insu Yun wrote:
> On Thu, Oct 15, 2015 at 1:17 PM, Dave Goodell (dgoodell) <dgoodell@cisco.com
> > wrote:
> 
> > On Oct 15, 2015, at 11:27 AM, Insu Yun <wuninsu@gmail.com> wrote:
> > >
> > >       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.
> >
> 
>   Do you think what is better? removing error code? or change
> PTR_ERR(us_ibdev->ufdev)
> to -EFAULT

I would write it as:

        usnic_err("Failed to alloc ufdev for %s\n", pci_name(dev));

-Dave

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-10-15 20:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-15 16:27 [PATCH] usnic: corretly check failed allocation Insu Yun
2015-10-15 17:17 ` Dave Goodell (dgoodell)
     [not found]   ` <CAGoFzNdD+b1co+6zsEo94KP3APLk353fwOQkgdMjh01UOG-9Ng@mail.gmail.com>
2015-10-15 20:52     ` Dave Goodell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®