lkml.org 
[lkml]   [2022]   [Jun]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] drm/ingenic: Use resource_size function on resource object
Hi,

Le ven., juin 24 2022 at 09:31:59 +0800, Jiapeng Chong
<jiapeng.chong@linux.alibaba.com> a écrit :
> This was found by coccicheck:
>
> ./drivers/gpu/drm/ingenic/ingenic-drm-drv.c:1149:35-38: WARNING:
> Suspicious code. resource_size is maybe missing with res.
>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> index 2c559885347a..5514b163999f 100644
> --- a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> +++ b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
> @@ -1146,7 +1146,7 @@ static int ingenic_drm_bind(struct device *dev,
> bool has_components)
> }
>
> regmap_config = ingenic_drm_regmap_config;
> - regmap_config.max_register = res->end - res->start;
> + regmap_config.max_register = resource_size(res);

These two are not equivalent. resource_size() is (res->end - res->start
+ 1).

If the memory resource has a size of 0x10 bytes, then using
resource_size() will set .max_register == 0x10, which is invalid, as it
is already outside the memory resource.

Cheers,
-Paul


> priv->map = devm_regmap_init_mmio(dev, base,
> &regmap_config);
> if (IS_ERR(priv->map)) {
> --
> 2.20.1.7.g153144c
>


\
 
 \ /
  Last update: 2022-06-24 21:01    [W:0.035 / U:12.280 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site