All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] macintosh: macio_asic: fix resource_size.cocci warnings
@ 2022-04-14 14:02 Yihao Han
  2022-04-19  7:54   ` Uwe Kleine-König
  2022-04-22  6:44 ` Michael Ellerman
  0 siblings, 2 replies; 6+ messages in thread
From: Yihao Han @ 2022-04-14 14:02 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Ulf Hansson, Mark Brown,
	Srinivas Pandruvada, William Breathitt Gray, Sven Van Asbroeck,
	Corentin Labbe, Yihao Han, Uwe Kleine-König, linuxppc-dev,
	linux-kernel
  Cc: kernel

drivers/macintosh/macio_asic.c:219:26-29: WARNING:
Suspicious code. resource_size is maybe missing with res
drivers/macintosh/macio_asic.c:221:26-29: WARNING:
Suspicious code. resource_size is maybe missing with res

Use resource_size function on resource object instead of
explicit computation.

Generated by: scripts/coccinelle/api/resource_size.cocci

Signed-off-by: Yihao Han <hanyihao@vivo.com>
---
 drivers/macintosh/macio_asic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 1943a007e2d5..260fccb3863e 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -216,9 +216,9 @@ static int macio_resource_quirks(struct device_node *np, struct resource *res,
 	/* Some older IDE resources have bogus sizes */
 	if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") ||
 	    of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) {
-		if (index == 0 && (res->end - res->start) > 0xfff)
+		if (index == 0 && (resource_size(res)) > 0xfff)
 			res->end = res->start + 0xfff;
-		if (index == 1 && (res->end - res->start) > 0xff)
+		if (index == 1 && (resource_size(res)) > 0xff)
 			res->end = res->start + 0xff;
 	}
 	return 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] macintosh: macio_asic: fix resource_size.cocci warnings
  2022-04-14 14:02 [PATCH] macintosh: macio_asic: fix resource_size.cocci warnings Yihao Han
@ 2022-04-19  7:54   ` Uwe Kleine-König
  2022-04-22  6:44 ` Michael Ellerman
  1 sibling, 0 replies; 6+ messages in thread
From: Uwe Kleine-König @ 2022-04-19  7:54 UTC (permalink / raw)
  To: Yihao Han
  Cc: Benjamin Herrenschmidt, Ulf Hansson, Mark Brown,
	Srinivas Pandruvada, William Breathitt Gray, Sven Van Asbroeck,
	Corentin Labbe, linuxppc-dev, linux-kernel, kernel

[-- Attachment #1: Type: text/plain, Size: 1638 bytes --]

On Thu, Apr 14, 2022 at 07:02:42AM -0700, Yihao Han wrote:
> drivers/macintosh/macio_asic.c:219:26-29: WARNING:
> Suspicious code. resource_size is maybe missing with res
> drivers/macintosh/macio_asic.c:221:26-29: WARNING:
> Suspicious code. resource_size is maybe missing with res

For log messages it's ok to overstep the line length limitation for
commit logs. IMHO adding newlines is worse, not sure that there are no
other strong opinions though.

> Use resource_size function on resource object instead of
> explicit computation.
> 
> Generated by: scripts/coccinelle/api/resource_size.cocci
> 
> Signed-off-by: Yihao Han <hanyihao@vivo.com>
> ---
>  drivers/macintosh/macio_asic.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
> index 1943a007e2d5..260fccb3863e 100644
> --- a/drivers/macintosh/macio_asic.c
> +++ b/drivers/macintosh/macio_asic.c
> @@ -216,9 +216,9 @@ static int macio_resource_quirks(struct device_node *np, struct resource *res,
>  	/* Some older IDE resources have bogus sizes */
>  	if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") ||
>  	    of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) {
> -		if (index == 0 && (res->end - res->start) > 0xfff)
> +		if (index == 0 && (resource_size(res)) > 0xfff)

You can drop the parenthesis around resource_size(res) here.

Other than that looks fine,
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] macintosh: macio_asic: fix resource_size.cocci warnings
@ 2022-04-19  7:54   ` Uwe Kleine-König
  0 siblings, 0 replies; 6+ messages in thread
From: Uwe Kleine-König @ 2022-04-19  7:54 UTC (permalink / raw)
  To: Yihao Han
  Cc: Sven Van Asbroeck, Ulf Hansson, William Breathitt Gray,
	linux-kernel, kernel, Mark Brown, Corentin Labbe,
	Srinivas Pandruvada, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 1638 bytes --]

On Thu, Apr 14, 2022 at 07:02:42AM -0700, Yihao Han wrote:
> drivers/macintosh/macio_asic.c:219:26-29: WARNING:
> Suspicious code. resource_size is maybe missing with res
> drivers/macintosh/macio_asic.c:221:26-29: WARNING:
> Suspicious code. resource_size is maybe missing with res

For log messages it's ok to overstep the line length limitation for
commit logs. IMHO adding newlines is worse, not sure that there are no
other strong opinions though.

> Use resource_size function on resource object instead of
> explicit computation.
> 
> Generated by: scripts/coccinelle/api/resource_size.cocci
> 
> Signed-off-by: Yihao Han <hanyihao@vivo.com>
> ---
>  drivers/macintosh/macio_asic.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
> index 1943a007e2d5..260fccb3863e 100644
> --- a/drivers/macintosh/macio_asic.c
> +++ b/drivers/macintosh/macio_asic.c
> @@ -216,9 +216,9 @@ static int macio_resource_quirks(struct device_node *np, struct resource *res,
>  	/* Some older IDE resources have bogus sizes */
>  	if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") ||
>  	    of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) {
> -		if (index == 0 && (res->end - res->start) > 0xfff)
> +		if (index == 0 && (resource_size(res)) > 0xfff)

You can drop the parenthesis around resource_size(res) here.

Other than that looks fine,
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] macintosh: macio_asic: fix resource_size.cocci warnings
  2022-04-14 14:02 [PATCH] macintosh: macio_asic: fix resource_size.cocci warnings Yihao Han
  2022-04-19  7:54   ` Uwe Kleine-König
@ 2022-04-22  6:44 ` Michael Ellerman
  2022-04-25 17:23     ` Uwe Kleine-König
  1 sibling, 1 reply; 6+ messages in thread
From: Michael Ellerman @ 2022-04-22  6:44 UTC (permalink / raw)
  To: Yihao Han, Benjamin Herrenschmidt, Ulf Hansson, Mark Brown,
	Srinivas Pandruvada, William Breathitt Gray, Sven Van Asbroeck,
	Corentin Labbe, Yihao Han, Uwe Kleine-König, linuxppc-dev,
	linux-kernel
  Cc: kernel

Yihao Han <hanyihao@vivo.com> writes:
> drivers/macintosh/macio_asic.c:219:26-29: WARNING:
> Suspicious code. resource_size is maybe missing with res
> drivers/macintosh/macio_asic.c:221:26-29: WARNING:
> Suspicious code. resource_size is maybe missing with res
>
> Use resource_size function on resource object instead of
> explicit computation.
>
> Generated by: scripts/coccinelle/api/resource_size.cocci
>
> Signed-off-by: Yihao Han <hanyihao@vivo.com>
> ---
>  drivers/macintosh/macio_asic.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
> index 1943a007e2d5..260fccb3863e 100644
> --- a/drivers/macintosh/macio_asic.c
> +++ b/drivers/macintosh/macio_asic.c
> @@ -216,9 +216,9 @@ static int macio_resource_quirks(struct device_node *np, struct resource *res,
>  	/* Some older IDE resources have bogus sizes */
>  	if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") ||
>  	    of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) {
> -		if (index == 0 && (res->end - res->start) > 0xfff)
> +		if (index == 0 && (resource_size(res)) > 0xfff)
>  			res->end = res->start + 0xfff;
> -		if (index == 1 && (res->end - res->start) > 0xff)
> +		if (index == 1 && (resource_size(res)) > 0xff)

Are you sure the conversion is correct? It's not exactly equivalent:

static inline resource_size_t resource_size(const struct resource *res)
{
	return res->end - res->start + 1;
}

cheers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] macintosh: macio_asic: fix resource_size.cocci warnings
  2022-04-22  6:44 ` Michael Ellerman
@ 2022-04-25 17:23     ` Uwe Kleine-König
  0 siblings, 0 replies; 6+ messages in thread
From: Uwe Kleine-König @ 2022-04-25 17:23 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Sven Van Asbroeck, Ulf Hansson, Yihao Han,
	William Breathitt Gray, linux-kernel, kernel, Mark Brown,
	Corentin Labbe, Srinivas Pandruvada, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 850 bytes --]

Hello Michael,

On Fri, Apr 22, 2022 at 04:44:24PM +1000, Michael Ellerman wrote:
> Yihao Han <hanyihao@vivo.com> writes:
> > -		if (index == 0 && (res->end - res->start) > 0xfff)
> > +		if (index == 0 && (resource_size(res)) > 0xfff)
> >  			res->end = res->start + 0xfff;
> > -		if (index == 1 && (res->end - res->start) > 0xff)
> > +		if (index == 1 && (resource_size(res)) > 0xff)
> 
> Are you sure the conversion is correct? It's not exactly equivalent:
> 
> static inline resource_size_t resource_size(const struct resource *res)
> {
> 	return res->end - res->start + 1;
> }

Indeed. I pointed out this issue in the v2 that already hit my inbox.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] macintosh: macio_asic: fix resource_size.cocci warnings
@ 2022-04-25 17:23     ` Uwe Kleine-König
  0 siblings, 0 replies; 6+ messages in thread
From: Uwe Kleine-König @ 2022-04-25 17:23 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Yihao Han, Benjamin Herrenschmidt, Ulf Hansson, Mark Brown,
	Srinivas Pandruvada, William Breathitt Gray, Sven Van Asbroeck,
	Corentin Labbe, linuxppc-dev, linux-kernel, kernel

[-- Attachment #1: Type: text/plain, Size: 850 bytes --]

Hello Michael,

On Fri, Apr 22, 2022 at 04:44:24PM +1000, Michael Ellerman wrote:
> Yihao Han <hanyihao@vivo.com> writes:
> > -		if (index == 0 && (res->end - res->start) > 0xfff)
> > +		if (index == 0 && (resource_size(res)) > 0xfff)
> >  			res->end = res->start + 0xfff;
> > -		if (index == 1 && (res->end - res->start) > 0xff)
> > +		if (index == 1 && (resource_size(res)) > 0xff)
> 
> Are you sure the conversion is correct? It's not exactly equivalent:
> 
> static inline resource_size_t resource_size(const struct resource *res)
> {
> 	return res->end - res->start + 1;
> }

Indeed. I pointed out this issue in the v2 that already hit my inbox.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-25 17:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14 14:02 [PATCH] macintosh: macio_asic: fix resource_size.cocci warnings Yihao Han
2022-04-19  7:54 ` Uwe Kleine-König
2022-04-19  7:54   ` Uwe Kleine-König
2022-04-22  6:44 ` Michael Ellerman
2022-04-25 17:23   ` Uwe Kleine-König
2022-04-25 17:23     ` Uwe Kleine-König

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.