public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
To: "Upinder Malhi (umalhi)"
	<umalhi-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
Cc: "<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>"
	<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: IB/usnic: Add Cisco VIC low-level hardware driver
Date: Thu, 12 Dec 2013 12:26:14 +0300	[thread overview]
Message-ID: <20131212092614.GT5443@mwanda> (raw)
In-Reply-To: <BC9EAC3B-33A6-482B-9CF4-DF1E1353AB3B-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>

On Thu, Dec 12, 2013 at 01:59:00AM +0000, Upinder Malhi (umalhi) wrote:
> Hi Dan,
> 	Can I ask what static checker you are using for these?
> 

In this email, the released version of Smatch will only warn about the
actual bug and not the others.  It requires that you build the cross
function database though before you test the code.

~/smatch/smatch_scripts/build_kernel_data.sh

> > drivers/infiniband/hw/usnic/usnic_uiom.c
> >   469          pd->domain = domain = iommu_domain_alloc(&pci_bus_type);
> >                                      ^^^^^^^^^^^^^^^^^^^
> > This function returns NULL on error not error pointers.
> > 
> >   470          if (IS_ERR_OR_NULL(domain)) {
> >   471                  usnic_err("Failed to allocate IOMMU domain with err %ld\n",
> >   472                                  PTR_ERR(pd->domain));
> >   473                  kfree(pd);
> >   474                  return ERR_PTR(domain ? PTR_ERR(domain) : -ENOMEM);
> >   475          }
> > 
> > Similar harmless but crappy slop in:
> [UM] - Unless I'm missing something, I think this is OK and preferred
> in case iommu_domain_alloc in future starts returning ERR_PTRs.

It doesn't cause a bug, but it's unusual and considered sloppy.  APIs
should be clear about what error codes they return and they should
almost always return either ERR_PTRs *or* NULL but not *both*.  The
exceptions are when NULL is a valid return which means something.  For
example, maybe you are looking for a file and you return NULL if the
file is not found but ERR_PTR(-ENOMEM) if you have an error.

In linux if we decide that iommu_domain_alloc() should return ERR_PTRs
instead of NULL pointers, then it's up to the person who decides that
to change all the callers as well.

Also if you trust the lower levels to print their error messages
correctly then the error handling here could be much simpler.  kzalloc()
for example, has very extensive error messages.

	pd->domain = domain = iommu_domain_alloc(&pci_bus_type);
	if (!domain) {
		kfree(pd);
		return -ENOMEM;
	}

regards,
dan carpenter


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2013-12-12  9:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11 22:38 IB/usnic: Add Cisco VIC low-level hardware driver Dan Carpenter
     [not found] ` <20131211223834.GA3955-mgFCXtclrQlZLf2FXnZxJA@public.gmane.org>
2013-12-12  1:59   ` Upinder Malhi (umalhi)
     [not found]     ` <BC9EAC3B-33A6-482B-9CF4-DF1E1353AB3B-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
2013-12-12  9:26       ` Dan Carpenter [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-12-11 22:39 Dan Carpenter
2013-12-11 22:40 Dan Carpenter
     [not found] ` <20131211224019.GC3955-mgFCXtclrQlZLf2FXnZxJA@public.gmane.org>
2013-12-12  3:03   ` Upinder Malhi (umalhi)
     [not found]     ` <7E785E0E-85C8-498D-9269-46C95110BF53-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
2013-12-12  9:29       ` Dan Carpenter
2013-12-11 22:43 Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131212092614.GT5443@mwanda \
    --to=dan.carpenter-qhclzuegtsvqt0dzr+alfa@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=umalhi-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox