All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Cercueil <paul@crapouillou.net>
To: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: airlied@linux.ie, daniel@ffwll.ch, linux-mips@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Sam Ravnborg <sam@ravnborg.org>
Subject: Re: [PATCH] drm/ingenic: Use resource_size function on resource object
Date: Fri, 24 Jun 2022 20:00:05 +0100	[thread overview]
Message-ID: <5SWZDR.5KODQDXQB5142@crapouillou.net> (raw)
In-Reply-To: <20220624013159.88646-1-jiapeng.chong@linux.alibaba.com>

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
> 



WARNING: multiple messages have this Message-ID (diff)
From: Paul Cercueil <paul@crapouillou.net>
To: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: airlied@linux.ie, linux-mips@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Sam Ravnborg <sam@ravnborg.org>
Subject: Re: [PATCH] drm/ingenic: Use resource_size function on resource object
Date: Fri, 24 Jun 2022 20:00:05 +0100	[thread overview]
Message-ID: <5SWZDR.5KODQDXQB5142@crapouillou.net> (raw)
In-Reply-To: <20220624013159.88646-1-jiapeng.chong@linux.alibaba.com>

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
> 



  parent reply	other threads:[~2022-06-24 19:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24  1:31 [PATCH] drm/ingenic: Use resource_size function on resource object Jiapeng Chong
2022-06-24  1:31 ` Jiapeng Chong
2022-06-24 17:25 ` Sam Ravnborg
2022-06-24 19:00 ` Paul Cercueil [this message]
2022-06-24 19:00   ` Paul Cercueil
  -- strict thread matches above, loose matches on Subject: below --
2022-03-03  8:08 Jiapeng Chong
2022-03-03  8:08 ` Jiapeng Chong

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=5SWZDR.5KODQDXQB5142@crapouillou.net \
    --to=paul@crapouillou.net \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jiapeng.chong@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=sam@ravnborg.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.