All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
To: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Cc: Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>,
	Fabio Estevam
	<fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org>,
	Mike Turquette
	<mturquette-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Pavel Machek <pavel-+ZI9xUNit7I@public.gmane.org>,
	Len Brown <len.brown-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
	linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Rafael J. Wysocki" <rjw-KKrjLPT3xs0@public.gmane.org>,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH v4 2/8] reset: Add reset controller API
Date: Fri, 01 Mar 2013 13:00:56 -0700	[thread overview]
Message-ID: <513108F8.30902@wwwdotorg.org> (raw)
In-Reply-To: <1361878774-6382-3-git-send-email-p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

On 02/26/2013 04:39 AM, Philipp Zabel wrote:
> This adds a simple API for devices to request being reset
> by separate reset controller hardware and implements the
> reset signal device tree binding.

> diff --git a/drivers/reset/core.c b/drivers/reset/core.c

> +int of_reset_simple_xlate(struct reset_controller_dev *rcdev,
> +			  const struct of_phandle_args *reset_spec, u32 *flags)
> +{
> +	if (WARN_ON(reset_spec->args_count < rcdev->of_reset_n_cells))
> +		return -EINVAL;

Would != make more sense than < ?

> +
> +	if (reset_spec->args[0] >= rcdev->nr_resets)
> +		return -EINVAL;
> +
> +	if (flags)
> +		*flags = reset_spec->args[1];

if (flags)
    if (reset_spec->args_count > 1)
        *flags = reset_spec->args[1];
    else
        *flags = 0;

?

> +struct reset_control *reset_control_get(struct device *dev, const char *id)
...
> +	mutex_lock(&reset_controller_list_mutex);
> +	rcdev = NULL;
> +	list_for_each_entry(r, &reset_controller_list, list) {
> +		if (args.np == r->of_node) {
> +			rcdev = r;
> +			break;
> +		}
> +	}
> +	mutex_unlock(&reset_controller_list_mutex);

At this point, rcdev could be removed from that list, and perhaps even
start to point at free'd memory.

> +	of_node_put(args.np);
> +
> +	if (!rcdev)
> +		return ERR_PTR(-ENODEV);
> +
> +	rstc_id = rcdev->of_xlate(rcdev, &args, NULL);
> +	if (rstc_id < 0)
> +		return ERR_PTR(rstc_id);
> +
> +	try_module_get(rcdev->owner);

What about error-handling here?

I think you want to drop reset_controller_list_mutex only after the call
to try_module_get()?

> +static int devm_reset_control_match(struct device *dev, void *res, void *data)
> +{
> +	struct reset_control **rstc = res;
> +	if (!rstc || !*rstc) {
> +		WARN_ON(!rstc || !*rstc);

I think you can if (WARN_ON(...)).

I'm not sure if the error-checks are quite right though;
reset_control_get always returns an error-pointer for errors, never
NULL, so the pointer can't ever be NULL. If it somehow was (e.g. client
usage error), then that NULL pointer would never match anything, so the
error-check still wouldn't be useful.

I'm not sure why this is a ** here; below in devm_reset_control_put()
you pass a just a *; are you expected to pass &rstc there instead?

> +void devm_reset_control_put(struct reset_control *rstc)
> +{
> +	int ret;
> +
> +	ret = devres_release(rstc->dev, devm_reset_control_release,
> +			     devm_reset_control_match, rstc);
> +	if (ret)
> +		WARN_ON(ret);
> +}
> +EXPORT_SYMBOL_GPL(devm_reset_control_put);

WARNING: multiple messages have this Message-ID (diff)
From: swarren@wwwdotorg.org (Stephen Warren)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 2/8] reset: Add reset controller API
Date: Fri, 01 Mar 2013 13:00:56 -0700	[thread overview]
Message-ID: <513108F8.30902@wwwdotorg.org> (raw)
In-Reply-To: <1361878774-6382-3-git-send-email-p.zabel@pengutronix.de>

On 02/26/2013 04:39 AM, Philipp Zabel wrote:
> This adds a simple API for devices to request being reset
> by separate reset controller hardware and implements the
> reset signal device tree binding.

> diff --git a/drivers/reset/core.c b/drivers/reset/core.c

> +int of_reset_simple_xlate(struct reset_controller_dev *rcdev,
> +			  const struct of_phandle_args *reset_spec, u32 *flags)
> +{
> +	if (WARN_ON(reset_spec->args_count < rcdev->of_reset_n_cells))
> +		return -EINVAL;

Would != make more sense than < ?

> +
> +	if (reset_spec->args[0] >= rcdev->nr_resets)
> +		return -EINVAL;
> +
> +	if (flags)
> +		*flags = reset_spec->args[1];

if (flags)
    if (reset_spec->args_count > 1)
        *flags = reset_spec->args[1];
    else
        *flags = 0;

?

> +struct reset_control *reset_control_get(struct device *dev, const char *id)
...
> +	mutex_lock(&reset_controller_list_mutex);
> +	rcdev = NULL;
> +	list_for_each_entry(r, &reset_controller_list, list) {
> +		if (args.np == r->of_node) {
> +			rcdev = r;
> +			break;
> +		}
> +	}
> +	mutex_unlock(&reset_controller_list_mutex);

At this point, rcdev could be removed from that list, and perhaps even
start to point at free'd memory.

> +	of_node_put(args.np);
> +
> +	if (!rcdev)
> +		return ERR_PTR(-ENODEV);
> +
> +	rstc_id = rcdev->of_xlate(rcdev, &args, NULL);
> +	if (rstc_id < 0)
> +		return ERR_PTR(rstc_id);
> +
> +	try_module_get(rcdev->owner);

What about error-handling here?

I think you want to drop reset_controller_list_mutex only after the call
to try_module_get()?

> +static int devm_reset_control_match(struct device *dev, void *res, void *data)
> +{
> +	struct reset_control **rstc = res;
> +	if (!rstc || !*rstc) {
> +		WARN_ON(!rstc || !*rstc);

I think you can if (WARN_ON(...)).

I'm not sure if the error-checks are quite right though;
reset_control_get always returns an error-pointer for errors, never
NULL, so the pointer can't ever be NULL. If it somehow was (e.g. client
usage error), then that NULL pointer would never match anything, so the
error-check still wouldn't be useful.

I'm not sure why this is a ** here; below in devm_reset_control_put()
you pass a just a *; are you expected to pass &rstc there instead?

> +void devm_reset_control_put(struct reset_control *rstc)
> +{
> +	int ret;
> +
> +	ret = devres_release(rstc->dev, devm_reset_control_release,
> +			     devm_reset_control_match, rstc);
> +	if (ret)
> +		WARN_ON(ret);
> +}
> +EXPORT_SYMBOL_GPL(devm_reset_control_put);

  parent reply	other threads:[~2013-03-01 20:00 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-26 11:39 [PATCH v4 0/8] Reset controller API to reset IP modules on i.MX5 and i.MX6 Philipp Zabel
2013-02-26 11:39 ` Philipp Zabel
2013-02-26 11:39 ` [PATCH v4 1/8] dt: describe base reset signal binding Philipp Zabel
2013-02-26 11:39   ` Philipp Zabel
2013-02-26 11:39 ` [PATCH v4 2/8] reset: Add reset controller API Philipp Zabel
2013-02-26 11:39   ` Philipp Zabel
     [not found]   ` <1361878774-6382-3-git-send-email-p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-03-01 20:00     ` Stephen Warren [this message]
2013-03-01 20:00       ` Stephen Warren
2013-03-04  8:33       ` Philipp Zabel
2013-03-04  8:33         ` Philipp Zabel
2013-03-04 17:03         ` Stephen Warren
2013-03-04 17:03           ` Stephen Warren
2013-02-26 11:39 ` [PATCH v4 3/8] ARM i.MX6q: Add GPU, VPU, IPU, and OpenVG resets to System Reset Controller (SRC) Philipp Zabel
2013-02-26 11:39   ` Philipp Zabel
2013-03-01 20:05   ` Stephen Warren
2013-03-01 20:05     ` Stephen Warren
     [not found]     ` <51310A12.1040209-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-03-01 20:07       ` Stephen Warren
2013-03-01 20:07         ` Stephen Warren
2013-02-26 11:39 ` [PATCH v4 4/8] ARM i.MX6q: Link system reset controller (SRC) to IPU in DT Philipp Zabel
2013-02-26 11:39   ` Philipp Zabel
2013-02-26 11:39 ` [PATCH v4 5/8] staging: drm/imx: Use SRC to reset IPU Philipp Zabel
2013-02-26 11:39   ` Philipp Zabel
2013-02-26 11:39 ` [PATCH v4 6/8] ARM i.MX5: Add System Reset Controller (SRC) support for i.MX51 and i.MX53 Philipp Zabel
2013-02-26 11:39   ` Philipp Zabel
2013-02-26 11:39 ` [PATCH v4 7/8] ARM i.MX5: Add system reset controller (SRC) to i.MX51 and i.MX53 device tree Philipp Zabel
2013-02-26 11:39   ` Philipp Zabel
2013-02-26 11:39 ` [PATCH v4 8/8] reset: Add driver for gpio-controlled reset pins Philipp Zabel
2013-02-26 11:39   ` Philipp Zabel
2013-03-01 20:13   ` Stephen Warren
2013-03-01 20:13     ` Stephen Warren
2013-05-27 16:25   ` Fabio Estevam
2013-05-27 16:25     ` Fabio Estevam
2013-05-28 15:05     ` Philipp Zabel
2013-05-28 15:05       ` Philipp Zabel

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=513108F8.30902@wwwdotorg.org \
    --to=swarren-3lzwwm7+weoh9zmkesr00q@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=len.brown-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=marex-ynQEQJNshbs@public.gmane.org \
    --cc=mturquette-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=pavel-+ZI9xUNit7I@public.gmane.org \
    --cc=rjw-KKrjLPT3xs0@public.gmane.org \
    --cc=s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.