Re: [PATCH 5/6] drivers: base: Share code for dev_request_mem_region*()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>

Using functions that takes a boolean to do two different things
is not an improvement.
At least not when the functions are this small and obvious.

This is not in the public interface, only a few static
functions which helps a lot.

Well, thats my personal preference, and in this case
not something I feel strong about.

	Sam


> ---
>  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@xxxxxxxxxxxxxxxxxxx
> http://lists.infradead.org/mailman/listinfo/barebox

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



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux