All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 5/6] drivers: base: Share code for dev_request_mem_region*()
Date: Sat, 27 Oct 2018 10:26:56 +0200	[thread overview]
Message-ID: <20181027082656.GC28052@ravnborg.org> (raw)
In-Reply-To: <20181027013230.24387-6-andrew.smirnov@gmail.com>

Hi Andrey,

On Fri, Oct 26, 2018 at 06:32:29PM -0700, Andrey Smirnov wrote:
> Both dev_request_mem_region() and dev_request_mem_region_err_null()
> implement exactly the same functionality different only in error
> reporting value. Change the code to make use of a common generic
> function whose return type can be specified via an argument.

Same story as PATCH 6/6 where a helper functions does
two things depending on a bool.
For simple functions like this my personal preference
is to keep the small functions that are more explicit.

	Sam

> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  drivers/base/driver.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> index c687afd75..476f844be 100644
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -407,27 +407,27 @@ struct resource *dev_request_mem_resource(struct device_d *dev, int num)
>  	return request_iomem_region(dev_name(dev), res->start, res->end);
>  }
>  
> -void __iomem *dev_request_mem_region_err_null(struct device_d *dev, int num)
> +static void __iomem *__dev_request_mem_region(struct device_d *dev, int num,
> +					      bool null_on_error)
>  {
>  	struct resource *res;
>  
>  	res = dev_request_mem_resource(dev, num);
>  	if (IS_ERR(res))
> -		return NULL;
> +		return null_on_error ? NULL : ERR_CAST(res);
>  
>  	return IOMEM(res->start);
>  }
> +
> +void __iomem *dev_request_mem_region_err_null(struct device_d *dev, int num)
> +{
> +	return __dev_request_mem_region(dev, num, true);
> +}
>  EXPORT_SYMBOL(dev_request_mem_region_err_null);
>  
>  void __iomem *dev_request_mem_region(struct device_d *dev, int num)
>  {
> -	struct resource *res;
> -
> -	res = dev_request_mem_resource(dev, num);
> -	if (IS_ERR(res))
> -		return ERR_CAST(res);
> -
> -	return IOMEM(res->start);
> +	return __dev_request_mem_region(dev, num, false);
>  }
>  EXPORT_SYMBOL(dev_request_mem_region);
>  
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2018-10-27  8:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-27  1:32 [PATCH 0/6] Refactor driver resource allocation code Andrey Smirnov
2018-10-27  1:32 ` [PATCH 1/6] drivers: base: Simplify generic_memmap_ro() Andrey Smirnov
2018-10-27  7:47   ` Sam Ravnborg
2018-10-27  1:32 ` [PATCH 2/6] drivers: base: Drop dev_get_mem_region_by_name() Andrey Smirnov
2018-10-27  1:32 ` [PATCH 3/6] drivers: base: Share implementations for dev_get_resource*() Andrey Smirnov
2018-10-29  8:52   ` Sascha Hauer
2018-10-27  1:32 ` [PATCH 4/6] drivers: base: Simplify dev_request_mem_region_err_null() Andrey Smirnov
2018-10-27  1:32 ` [PATCH 5/6] drivers: base: Share code for dev_request_mem_region*() Andrey Smirnov
2018-10-27  8:20   ` Sam Ravnborg
2018-10-29  8:58     ` Sascha Hauer
2018-10-27  8:26   ` Sam Ravnborg [this message]
2018-10-27  8:46     ` Sam Ravnborg
2018-10-27  1:32 ` [PATCH 6/6] drivers: base: Share code for getting and then requesting a region Andrey Smirnov
2018-10-29  9:00 ` [PATCH 0/6] Refactor driver resource allocation code Sascha Hauer

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=20181027082656.GC28052@ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.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.