lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9cf60cb8-8ff7-c5d1-1bfe-4c5c1df7eabf@c-s.fr>
Date:   Tue, 16 Jan 2018 13:18:41 +0100
From:   Christophe LEROY <christophe.leroy@....fr>
To:     Yisheng Xie <xieyisheng1@...wei.com>, gregkh@...uxfoundation.org
Cc:     thomas.lendacky@....com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5] devres: combine function devm_ioremap*



Le 16/01/2018 à 13:03, Yisheng Xie a écrit :
> When I tried to use devm_ioremap function and review related
> code, I found devm_ioremap_* almost have the similar realize
> with each other, which can be combined.
> 
> In the former version, I have tried to kill ioremap_cache to
> reduce the size of devres, which can not work for ioremap is
> not the same as ioremap_nocache in some ARCHs likes ia64.
> Therefore, as the suggestion of Christophe, I introduce a help
> function __devm_ioremap, let devm_ioremap* inline and call
> __devm_ioremap with different devm_ioremap_type.
> 
> After apply the patch, the size of devres.o can be reduce from
> 8216 Bytes to 7352Bytes in my compile environment.
> 
> Suggested-by: Christophe LEROY <christophe.leroy@....fr>
> Signed-off-by: Yisheng Xie <xieyisheng1@...wei.com>

Review-by: Christophe LEROY <christophe.leroy@....fr>

> ---
> v2:
>   - use MARCO for ioremap
> v3:
>   - kill dev_ioremap_nocache
> v4:
>   - combine function devm_ioremap*
> v5:
>   - fix code style.
> 
>   include/linux/io.h | 61 +++++++++++++++++++++++++++++++++++----
>   lib/devres.c       | 84 ++++++++++--------------------------------------------
>   2 files changed, 70 insertions(+), 75 deletions(-)
> 
> diff --git a/include/linux/io.h b/include/linux/io.h
> index 32e30e8..4d0a640 100644
> --- a/include/linux/io.h
> +++ b/include/linux/io.h
> @@ -73,12 +73,61 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
>   
>   #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
>   
> -void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
> -			   resource_size_t size);
> -void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
> -				   resource_size_t size);
> -void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
> -				   resource_size_t size);
> +enum devm_ioremap_type {
> +	DEVM_IOREMAP = 0,
> +	DEVM_IOREMAP_NC,
> +	DEVM_IOREMAP_WC,
> +};
> +
> +void __iomem *__devm_ioremap(struct device *dev, resource_size_t offset,
> +			     resource_size_t size, enum devm_ioremap_type type);
> +
> +/**
> + * devm_ioremap - Managed ioremap()
> + * @dev: Generic device to remap IO address for
> + * @offset: Resource address to map
> + * @size: Size of map
> + *
> + * Managed ioremap().  Map is automatically unmapped on driver detach.
> + */
> +static inline void __iomem *devm_ioremap(struct device *dev,
> +					 resource_size_t offset,
> +					 resource_size_t size)
> +{
> +	return __devm_ioremap(dev, offset, size, DEVM_IOREMAP);
> +}
> +
> +/**
> + * devm_ioremap_nocache - Managed ioremap_nocache()
> + * @dev: Generic device to remap IO address for
> + * @offset: Resource address to map
> + * @size: Size of map
> + *
> + * Managed ioremap_nocache().  Map is automatically unmapped on driver
> + * detach.
> + */
> +static inline void __iomem *devm_ioremap_nocache(struct device *dev,
> +						 resource_size_t offset,
> +						 resource_size_t size)
> +{
> +	return __devm_ioremap(dev, offset, size, DEVM_IOREMAP_NC);
> +}
> +
> +/**
> + * devm_ioremap_wc - Managed ioremap_wc()
> + * @dev: Generic device to remap IO address for
> + * @offset: Resource address to map
> + * @size: Size of map
> + *
> + * Managed ioremap_wc().  Map is automatically unmapped on driver detach.
> + */
> +static inline void __iomem *devm_ioremap_wc(struct device *dev,
> +					    resource_size_t offset,
> +					    resource_size_t size)
> +{
> +	return __devm_ioremap(dev, offset, size, DEVM_IOREMAP_WC);
> +}
> +
>   void devm_iounmap(struct device *dev, void __iomem *addr);
>   int check_signature(const volatile void __iomem *io_addr,
>   			const unsigned char *signature, int length);
> diff --git a/lib/devres.c b/lib/devres.c
> index 5f2aedd..88a4520 100644
> --- a/lib/devres.c
> +++ b/lib/devres.c
> @@ -15,81 +15,27 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data)
>   	return *(void **)res == match_data;
>   }
>   
> -/**
> - * devm_ioremap - Managed ioremap()
> - * @dev: Generic device to remap IO address for
> - * @offset: Resource address to map
> - * @size: Size of map
> - *
> - * Managed ioremap().  Map is automatically unmapped on driver detach.
> - */
> -void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
> -			   resource_size_t size)
> +void __iomem *__devm_ioremap(struct device *dev, resource_size_t offset,
> +			     resource_size_t size, enum devm_ioremap_type type)
>   {
> -	void __iomem **ptr, *addr;
> +	void __iomem **ptr, *addr = NULL;
>   
>   	ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL);
>   	if (!ptr)
>   		return NULL;
>   
> -	addr = ioremap(offset, size);
> -	if (addr) {
> -		*ptr = addr;
> -		devres_add(dev, ptr);
> -	} else
> -		devres_free(ptr);
> -
> -	return addr;
> -}
> -EXPORT_SYMBOL(devm_ioremap);
> -
> -/**
> - * devm_ioremap_nocache - Managed ioremap_nocache()
> - * @dev: Generic device to remap IO address for
> - * @offset: Resource address to map
> - * @size: Size of map
> - *
> - * Managed ioremap_nocache().  Map is automatically unmapped on driver
> - * detach.
> - */
> -void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
> -				   resource_size_t size)
> -{
> -	void __iomem **ptr, *addr;
> -
> -	ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return NULL;
> -
> -	addr = ioremap_nocache(offset, size);
> -	if (addr) {
> -		*ptr = addr;
> -		devres_add(dev, ptr);
> -	} else
> -		devres_free(ptr);
> -
> -	return addr;
> -}
> -EXPORT_SYMBOL(devm_ioremap_nocache);
> -
> -/**
> - * devm_ioremap_wc - Managed ioremap_wc()
> - * @dev: Generic device to remap IO address for
> - * @offset: Resource address to map
> - * @size: Size of map
> - *
> - * Managed ioremap_wc().  Map is automatically unmapped on driver detach.
> - */
> -void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
> -			      resource_size_t size)
> -{
> -	void __iomem **ptr, *addr;
> -
> -	ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return NULL;
> +	switch (type) {
> +	case DEVM_IOREMAP:
> +		addr = ioremap(offset, size);
> +		break;
> +	case DEVM_IOREMAP_NC:
> +		addr = ioremap_nocache(offset, size);
> +		break;
> +	case DEVM_IOREMAP_WC:
> +		addr = ioremap_wc(offset, size);
> +		break;
> +	}
>   
> -	addr = ioremap_wc(offset, size);
>   	if (addr) {
>   		*ptr = addr;
>   		devres_add(dev, ptr);
> @@ -98,7 +44,7 @@ void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
>   
>   	return addr;
>   }
> -EXPORT_SYMBOL(devm_ioremap_wc);
> +EXPORT_SYMBOL(__devm_ioremap);
>   
>   /**
>    * devm_iounmap - Managed iounmap()
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ