From: Ingo Molnar <mingo@kernel.org>
To: Toshi Kani <toshi.kani@hpe.com>
Cc: bp@suse.de, dan.j.williams@intel.com, rjw@rjwysocki.net,
akpm@linux-foundation.org, linux-nvdimm@ml01.01.org,
linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH v2-UPDATE 3/4] resource: Add device-managed insert/remove_resource()
Date: Tue, 8 Mar 2016 13:02:53 +0100 [thread overview]
Message-ID: <20160308120253.GA3599@gmail.com> (raw)
In-Reply-To: <1457108082-4610-1-git-send-email-toshi.kani@hpe.com>
* Toshi Kani <toshi.kani@hpe.com> wrote:
> +/**
> + * devm_insert_resource() - insert an I/O or memory resource
> + * @dev: device for which to produce the resource
> + * @root: root of the resource tree
> + * @new: descriptor of the new resource
> + *
> + * This is a device-managed version of insert_resource(). There is usually
> + * no need to release resources requested by this function explicitly since
s/explicitly since
/explicitly, since
> + * that will be taken care of when the device is unbound from its bus driver.
> + * If for some reason the resource needs to be released explicitly, because
> + * of ordering issues for example, bus drivers must call devm_remove_resource()
> + * rather than the regular remove_resource().
> + *
> + * devm_insert_resource() is intended for producers of resources, such as
> + * FW modules and bus drivers.
> + *
> + * Returns 0 on success or a negative error code on failure.
> + */
> +int devm_insert_resource(struct device *dev, struct resource *root,
> + struct resource *new)
> +{
> + struct resource **ptr;
> + int ret;
> +
> + ptr = devres_alloc(__devm_remove_resource, sizeof(*ptr), GFP_KERNEL);
> + if (!ptr)
> + return -ENOMEM;
> +
> + *ptr = new;
> +
> + ret = insert_resource(root, new);
> + if (ret) {
> + dev_err(dev, "unable to insert resource: %pR (%d)\n", new, ret);
> + devres_free(ptr);
> + return -EBUSY;
Why not return 'ret' here, instead of -EBUSY?
> + }
> +
> + devres_add(dev, ptr);
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(devm_insert_resource);
> +
> +/**
> + * devm_remove_resource() - remove a previously inserted resource
> + * @dev: device for which to remove the resource
> + * @old: descriptor of the resource
> + *
> + * Remove a resource previously inserted using devm_insert_resource().
> + *
> + * devm_remove_resource() is intended for producers of resources, such as
> + * FW modules and bus drivers.
> + */
> +void devm_remove_resource(struct device *dev, struct resource *old)
> +{
> + WARN_ON(devres_release(dev, __devm_remove_resource, devm_resource_match,
> + old));
So generally we don't put functions with side effects into WARN_ON()s. Just like
BUG_ON(), in the future it might be disabled on certain Kconfigs, etc. - and it's
also bad for readability.
Also, please use WARN_ON_ONCE().
> +}
> +EXPORT_SYMBOL_GPL(devm_remove_resource);
> +
> +/*
> * Called from init/main.c to reserve IO ports.
> */
> #define MAXRESERVE 4
Looks good to me otherwise.
Thanks,
Ingo
next prev parent reply other threads:[~2016-03-08 12:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-04 16:14 [PATCH v2-UPDATE 3/4] resource: Add device-managed insert/remove_resource() Toshi Kani
2016-03-07 18:14 ` Dan Williams
2016-03-07 23:03 ` Toshi Kani
2016-03-08 2:21 ` Dan Williams
2016-03-08 12:02 ` Ingo Molnar [this message]
2016-03-08 17:41 ` Toshi Kani
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=20160308120253.GA3599@gmail.com \
--to=mingo@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bp@suse.de \
--cc=dan.j.williams@intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@ml01.01.org \
--cc=rjw@rjwysocki.net \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=toshi.kani@hpe.com \
/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).