From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D3F0C433EF for ; Fri, 24 Jun 2022 19:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232185AbiFXTA0 (ORCPT ); Fri, 24 Jun 2022 15:00:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232206AbiFXTAT (ORCPT ); Fri, 24 Jun 2022 15:00:19 -0400 Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E1F081C5C; Fri, 24 Jun 2022 12:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1656097215; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=THNfze9JEECbMTbkniNl4WxsrwffazR6yHW49pczds4=; b=K941P0DpIoJDcsyNQjtu54obkjlHXfjLrCJBJoMhBy8bzMbVZkEcE5OXtUNtK5CFnOQVkC 6PUACCO5JqQSInC01JnI685UZIAKzhA5KZvrb3V5xUdLntYxsH1Uu/73nVZ7r6AM66/277 4NZVnmpuPNbMaBbBZIo99FOznMgIXUY= Date: Fri, 24 Jun 2022 20:00:05 +0100 From: Paul Cercueil Subject: Re: [PATCH] drm/ingenic: Use resource_size function on resource object To: Jiapeng Chong Cc: airlied@linux.ie, daniel@ffwll.ch, linux-mips@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sam Ravnborg Message-Id: <5SWZDR.5KODQDXQB5142@crapouillou.net> In-Reply-To: <20220624013159.88646-1-jiapeng.chong@linux.alibaba.com> References: <20220624013159.88646-1-jiapeng.chong@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Le ven., juin 24 2022 at 09:31:59 +0800, Jiapeng Chong=20 a =E9crit : > This was found by coccicheck: >=20 > ./drivers/gpu/drm/ingenic/ingenic-drm-drv.c:1149:35-38: WARNING:=20 > Suspicious code. resource_size is maybe missing with res. >=20 > Signed-off-by: Jiapeng Chong > --- > drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c=20 > 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,=20 > bool has_components) > } >=20 > regmap_config =3D ingenic_drm_regmap_config; > - regmap_config.max_register =3D res->end - res->start; > + regmap_config.max_register =3D resource_size(res); These two are not equivalent. resource_size() is (res->end - res->start=20 + 1). If the memory resource has a size of 0x10 bytes, then using=20 resource_size() will set .max_register =3D=3D 0x10, which is invalid, as it= =20 is already outside the memory resource. Cheers, -Paul > priv->map =3D devm_regmap_init_mmio(dev, base, > ®map_config); > if (IS_ERR(priv->map)) { > -- > 2.20.1.7.g153144c >=20