From: Thierry Reding <thierry.reding@gmail.com>
To: Tejun Heo <tj@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Stephen Warren <swarren@wwwdotorg.org>,
linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] resource: Add device-managed request/release_resource()
Date: Tue, 29 Jul 2014 13:33:04 +0200 [thread overview]
Message-ID: <20140729113302.GA21732@ulmo.nvidia.com> (raw)
In-Reply-To: <20140722190120.GM13851@htj.dyndns.org>
[-- Attachment #1: Type: text/plain, Size: 3035 bytes --]
On Tue, Jul 22, 2014 at 03:01:20PM -0400, Tejun Heo wrote:
> Hello,
>
> On Tue, Jul 22, 2014 at 12:50:02PM -0600, Bjorn Helgaas wrote:
> > [+cc Tejun, LKML]
> >
> > On Fri, Jul 11, 2014 at 09:08:24AM +0200, Thierry Reding wrote:
> > > From: Thierry Reding <treding@nvidia.com>
> > >
> > > Provide device-managed implementations of the request_resource() and
> > > release_resource() functions. Upon failure to request a resource, the
> > > new devm_request_resource() function will output an error message for
> > > consistent error reporting.
> > >
> > > Signed-off-by: Thierry Reding <treding@nvidia.com>
> >
> > This seems OK to me, but I don't consider myself a devres maintainer. I
> > added Tejun and LKML for any comment. Minor nit below.
>
> If there are gonna be users of the interface, sure.
>
> > > +int devm_request_resource(struct device *dev, struct resource *root,
> > > + struct resource *new)
> > > +{
> > > + struct resource *conflict, **ptr;
> > > +
> > > + ptr = devres_alloc(devm_resource_release, sizeof(*ptr), GFP_KERNEL);
> > > + if (!ptr)
> > > + return -ENOMEM;
> > > +
> > > + *ptr = new;
> > > +
> > > + conflict = request_resource_conflict(root, new);
> > > + if (!conflict) {
> > > + devres_add(dev, ptr);
> > > + return 0;
> > > + }
> > > +
> > > + dev_err(dev, "resource collision: %pR conflicts with %s %pR\n", new,
> > > + conflict->name, conflict);
> > > + devres_free(ptr);
> > > + return -EBUSY;
> >
> > Personally I would write this as:
> >
> > conflict = request_resource_conflict(...);
> > if (conflict) {
> > dev_err(...);
> > devres_free(...);
> > return -EBUSY;
> > }
> >
> > devres_add(...);
> > return 0;
> >
> > so the straight-line path is the normal, non-error path and errors are
> > detected and dealt with in the "if" bodies. Right now the "if" bodies
> > are a mix of error handling and normal path. But that's just my personal
> > preference.
>
> Agreed.
>
> > > +static int devm_resource_match(struct device *dev, void *res, void *data)
> > > +{
> > > + struct resource **ptr = res;
> > > +
> > > + if (WARN_ON(!ptr || !*ptr))
> > > + return 0;
>
> How would !ptr or !*ptr possibly happen? Wouldn't that be a bug
> already?
Honestly, I copied that from similar implementations. But checking the
code again, I don't think they can actually happen. The value returned
by devres_alloc() is a struct devres * with an added offset so that it
points at the payload immediately following the struct devres. So at
least !ptr can never happen.
!*ptr could happen since the devres code calls the match function on
every resource managed for the device and someone could've inserted a
NULL (or 0) value. But since we're not dereferencing *ptr this should
not be an issue. That said, having either res or data above be NULL
isn't something that devres was meant to deal with anyway, since it
relies on the pointers being unique for the matching.
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
prev parent reply other threads:[~2014-07-29 11:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-11 7:08 [PATCH 1/2] resource: Add device-managed request/release_resource() Thierry Reding
2014-07-11 7:08 ` [PATCH 2/2] PCI: tegra: Implement a proper resource hierarchy Thierry Reding
2014-07-21 15:58 ` Stephen Warren
2014-07-22 18:50 ` [PATCH 1/2] resource: Add device-managed request/release_resource() Bjorn Helgaas
2014-07-22 19:01 ` Tejun Heo
2014-07-29 11:33 ` Thierry Reding [this message]
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=20140729113302.GA21732@ulmo.nvidia.com \
--to=thierry.reding@gmail.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=swarren@wwwdotorg.org \
--cc=tj@kernel.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;
as well as URLs for NNTP newsgroup(s).