Skip to contentSkip to conversation

hwrng: make symbol 'optee_rng_id_table' static

PATCH Applied Wei Yongjun 8 participants 12 messages Feb 20, 2019 – Feb 21, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwrng: make symbol 'optee_rng_id_table' static

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

Fixes 5fe8b1cc6a03 ("hwrng: add OP-TEE based rng driver")
---
 drivers/char/hw_random/optee-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/optee-rng.c +1 -1
index 2b9fc8ac5500..3a4dd6fc9ff4 100644
@@ -262,7 +262,7 @@ static int optee_rng_remove(struct device *dev)
 	return 0;
 }
 
-const struct tee_client_device_id optee_rng_id_table[] = {
+static const struct tee_client_device_id optee_rng_id_table[] = {
 	{UUID_INIT(0xab7a617c, 0xb8e7, 0x4d8f,
 		   0x83, 0x01, 0xd0, 0x9b, 0x61, 0x03, 0x6b, 0x64)},
 	{}
#1 lore raw
Quoted 6 lines · Wei Yongjun

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

I haven't observed this warning during my normal Linux build using gcc. Is there any specific configuration you are using?

-Sumit

Quoted 22 lines
Fixes 5fe8b1cc6a03 ("hwrng: add OP-TEE based rng driver")
---
 drivers/char/hw_random/optee-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/optee-rng.c +1 -1
index 2b9fc8ac5500..3a4dd6fc9ff4 100644
@@ -262,7 +262,7 @@ static int optee_rng_remove(struct device *dev)
        return 0;
 }
 
-const struct tee_client_device_id optee_rng_id_table[] = {
+static const struct tee_client_device_id optee_rng_id_table[] = {
        {UUID_INIT(0xab7a617c, 0xb8e7, 0x4d8f,
                   0x83, 0x01, 0xd0, 0x9b, 0x61, 0x03, 0x6b, 0x64)},
        {}
#2 lore raw
Quoted 12 lines · Sumit Garg
Quoted 6 lines · Wei Yongjun

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

I haven't observed this warning during my normal Linux build using gcc. Is there any specific configuration you are using?

This is a sparse warning, not GCC. You need to install it separately and build with C=1 (iirc)

Quoted 22 lines
Quoted 22 lines
Fixes 5fe8b1cc6a03 ("hwrng: add OP-TEE based rng driver")
---
 drivers/char/hw_random/optee-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/optee-rng.c +1 -1
index 2b9fc8ac5500..3a4dd6fc9ff4 100644
@@ -262,7 +262,7 @@ static int optee_rng_remove(struct device *dev)
        return 0;
 }
 
-const struct tee_client_device_id optee_rng_id_table[] = {
+static const struct tee_client_device_id optee_rng_id_table[] = {
        {UUID_INIT(0xab7a617c, 0xb8e7, 0x4d8f,
                   0x83, 0x01, 0xd0, 0x9b, 0x61, 0x03, 0x6b, 0x64)},
        {}
#3 lore raw
Quoted 10 lines · Ard Biesheuvel
Quoted 9 lines · Sumit Garg
Quoted 6 lines · Wei Yongjun

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

Quoted 7 lines
Quoted 3 lines

I haven't observed this warning during my normal Linux build using gcc. Is there any specific configuration you are using?

This is a sparse warning, not GCC. You need to install it separately and build with C=1 (iirc)

It's useful to may these symbols static just to reduce the scope and there is on-going work to fix these symbols up across the entire kernel

#4 lore raw
Quoted 12 lines · Colin Ian King
Quoted 10 lines · Ard Biesheuvel
Quoted 9 lines · Sumit Garg
Quoted 6 lines · Wei Yongjun

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

I haven't observed this warning during my normal Linux build using gcc. Is there any specific configuration you are using?

This is a sparse warning, not GCC. You need to install it separately and build with C=1 (iirc)

TBH, I wasn't aware about this sparse tool. I did install sparse and build with C=1 option. But I could only get following such errors/warnings for drivers/char/hw_random/optee-rng.c:

./arch/arm64/include/asm/lse.h:18:37: warning: Unknown escape 'l' ./arch/arm64/include/asm/alternative.h:213:28: warning: Unknown escape 'o' ./include/linux/compiler.h:194:8: error: attribute '__gnu_inline__':
unknown attribute

But not the one mentioned in this patch.

Quoted 3 lines

It's useful to may these symbols static just to reduce the scope and there is on-going work to fix these symbols up across the entire kernel

Agree with this patch to make optee_rng_id_table symbol static. Actually I was curious to know the approach used to get these type of warnings so that they could be fixed beforehand.

-Sumit

#5 lore raw
Quoted 26 lines · Sumit Garg
Quoted 12 lines · Colin Ian King
Quoted 10 lines · Ard Biesheuvel
Quoted 9 lines · Sumit Garg
Quoted 6 lines · Wei Yongjun

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

I haven't observed this warning during my normal Linux build using gcc. Is there any specific configuration you are using?

This is a sparse warning, not GCC. You need to install it separately and build with C=1 (iirc)

TBH, I wasn't aware about this sparse tool. I did install sparse and build with C=1 option. But I could only get following such errors/warnings for drivers/char/hw_random/optee-rng.c:

Quoted 6 lines

./arch/arm64/include/asm/lse.h:18:37: warning: Unknown escape 'l' ./arch/arm64/include/asm/alternative.h:213:28: warning: Unknown escape 'o' ./include/linux/compiler.h:194:8: error: attribute '__gnu_inline__':
unknown attribute

But not the one mentioned in this patch.

Not sure what went wrong, I see the same warning as the others. Maybe you have an outdated version of sparse that runs into unrelated issues?

Quoted 7 lines
Quoted 3 lines

It's useful to may these symbols static just to reduce the scope and there is on-going work to fix these symbols up across the entire kernel

Agree with this patch to make optee_rng_id_table symbol static. Actually I was curious to know the approach used to get these type of warnings so that they could be fixed beforehand.

If you provide an 'Acked-by' or 'Reviewed-by' tag, I can apply this one on top of the other two fixes I already took.

I also recommend building with 'make W=1', which enables additional warnings and found this bug in your driver:

drivers/char/hw_random/optee-rng.c: In function 'get_optee_rng_data':
drivers/char/hw_random/optee-rng.c:94:11: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]

  if ((ret < 0) || (inv_arg.ret != 0)) {
           ^
drivers/char/hw_random/optee-rng.c: In function 'get_optee_rng_info':
drivers/char/hw_random/optee-rng.c:188:11: error: comparison of
unsigned expression < 0 is always false [-Werror=type-limits]
  if ((ret < 0) || (inv_arg.ret != 0)) {
           ^

Here, you probably need to make 'ret' an 'int', and you should drop the extraneous zero-initialization for a couple of variables like that one, so gcc is able to do its job of warning about uninitialized variable

Arnd

Reviewed-by
#6 lore raw

Hi Arnd,

Quoted 33 lines · Arnd Bergmann
Quoted 31 lines · Sumit Garg
Quoted 12 lines · Colin Ian King
Quoted 10 lines · Ard Biesheuvel
Quoted 9 lines · Sumit Garg
Quoted 6 lines · Wei Yongjun

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

I haven't observed this warning during my normal Linux build using gcc. Is there any specific configuration you are using?

This is a sparse warning, not GCC. You need to install it separately and build with C=1 (iirc)

TBH, I wasn't aware about this sparse tool. I did install sparse and build with C=1 option. But I could only get following such errors/warnings for drivers/char/hw_random/optee-rng.c:

./arch/arm64/include/asm/lse.h:18:37: warning: Unknown escape 'l' ./arch/arm64/include/asm/alternative.h:213:28: warning: Unknown escape 'o' ./include/linux/compiler.h:194:8: error: attribute '__gnu_inline__':
unknown attribute

Quoted 6 lines
Quoted 1 line

But not the one mentioned in this patch.

Not sure what went wrong, I see the same warning as the others. Maybe you have an outdated version of sparse that runs into unrelated issues?

$ apt list sparse
Listing... Done
sparse/xenial,now 0.5.0-1build1 amd64 [installed]
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

It's useful to may these symbols static just to reduce the scope and there is on-going work to fix these symbols up across the entire kernel

Agree with this patch to make optee_rng_id_table symbol static. Actually I was curious to know the approach used to get these type of warnings so that they could be fixed beforehand.

If you provide an 'Acked-by' or 'Reviewed-by' tag, I can apply this one on top of the other two fixes I already took.

Sure.

Quoted 1 line

I also recommend building with 'make W=1',

Thanks for your suggestion.

Quoted 14 lines

which enables additional
warnings and found this bug in your driver:

drivers/char/hw_random/optee-rng.c: In function 'get_optee_rng_data':
drivers/char/hw_random/optee-rng.c:94:11: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]

  if ((ret < 0) || (inv_arg.ret != 0)) {
           ^
drivers/char/hw_random/optee-rng.c: In function 'get_optee_rng_info':
drivers/char/hw_random/optee-rng.c:188:11: error: comparison of
unsigned expression < 0 is always false [-Werror=type-limits]
  if ((ret < 0) || (inv_arg.ret != 0)) {
           ^
Quoted 4 lines

Here, you probably need to make 'ret' an 'int', and you should drop the extraneous zero-initialization for a couple of variables like that one, so gcc is able to do its job of warning about uninitialized variable

There are already fixes sent in upstream for these. Maybe you could pick those too.

https://www.mail-archive.com/[email protected]/msg1935826.html
https://www.mail-archive.com/[email protected]/msg1935849.html

One more reported by Dan Carpenter here:

https://www.mail-archive.com/[email protected]/msg1936881.html

Thanks,
Sumit

Quoted 1 line

Arnd

#7 lore raw
Quoted 38 lines · Sumit Garg

Hi Arnd,

Quoted 35 lines · Arnd Bergmann
Quoted 32 lines · Sumit Garg
Quoted 12 lines · Colin Ian King
Quoted 10 lines · Ard Biesheuvel
Quoted 9 lines · Sumit Garg
Quoted 6 lines · Wei Yongjun

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

I haven't observed this warning during my normal Linux build using gcc. Is there any specific configuration you are using?

This is a sparse warning, not GCC. You need to install it separately and build with C=1 (iirc)

TBH, I wasn't aware about this sparse tool. I did install sparse and build with C=1 option. But I could only get following such errors/warnings for drivers/char/hw_random/optee-rng.c:

./arch/arm64/include/asm/lse.h:18:37: warning: Unknown escape 'l' ./arch/arm64/include/asm/alternative.h:213:28: warning: Unknown escape 'o' ./include/linux/compiler.h:194:8: error: attribute '__gnu_inline__':
unknown attribute

But not the one mentioned in this patch.

Quoted 8 lines
Quoted 4 lines

Not sure what went wrong, I see the same warning as the others. Maybe you have an outdated version of sparse that runs into unrelated issues?

$ apt list sparse
Listing... Done
sparse/xenial,now 0.5.0-1build1 amd64 [installed]

Ick, really obsolete, please use the sparse version on kernel.org for kernel stuff:
git://git.kernel.org/pub/scm/devel/sparse/sparse.git

Loads of things have been fixed and resolved from 0.5.0 which is very old.

thanks,

greg k-h

#8 lore raw
Quoted 49 lines · Greg Kroah-Hartman
Quoted 38 lines · Sumit Garg

Hi Arnd,

Quoted 35 lines · Arnd Bergmann
Quoted 32 lines · Sumit Garg
Quoted 12 lines · Colin Ian King
Quoted 10 lines · Ard Biesheuvel
Quoted 9 lines · Sumit Garg
Quoted 6 lines · Wei Yongjun

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

I haven't observed this warning during my normal Linux build using gcc. Is there any specific configuration you are using?

This is a sparse warning, not GCC. You need to install it separately and build with C=1 (iirc)

TBH, I wasn't aware about this sparse tool. I did install sparse and build with C=1 option. But I could only get following such errors/warnings for drivers/char/hw_random/optee-rng.c:

./arch/arm64/include/asm/lse.h:18:37: warning: Unknown escape 'l' ./arch/arm64/include/asm/alternative.h:213:28: warning: Unknown escape 'o' ./include/linux/compiler.h:194:8: error: attribute '__gnu_inline__':
unknown attribute

But not the one mentioned in this patch.

Quoted 8 lines
Quoted 4 lines

Not sure what went wrong, I see the same warning as the others. Maybe you have an outdated version of sparse that runs into unrelated issues?

$ apt list sparse
Listing... Done
sparse/xenial,now 0.5.0-1build1 amd64 [installed]
Quoted 7 lines

Ick, really obsolete, please use the sparse version on kernel.org for kernel stuff:
git://git.kernel.org/pub/scm/devel/sparse/sparse.git

Loads of things have been fixed and resolved from 0.5.0 which is very old.

Thanks for this info. Now it works pretty well.

-Sumit

Quoted 3 lines

thanks,

greg k-h

#9 lore raw
In reply to Sumit Garg
Quoted 7 lines · Sumit Garg

On Wed, 20 Feb 2019 at 21:04, Arnd Bergmann <[email protected]> wrote:

There are already fixes sent in upstream for these. Maybe you could pick those too.

Quoted 7 lines

https://www.mail-archive.com/[email protected]/msg1935826.html
https://www.mail-archive.com/[email protected]/msg1935849.html

One more reported by Dan Carpenter here:

https://www.mail-archive.com/[email protected]/msg1936881.html

Applied all for now, thanks a lot!

Arnd

#10 lore raw
In reply to Sumit Garg
Quoted 3 lines · Sumit Garg
Quoted 2 lines · Wei Yongjun

Fixes the following sparse warning:

                        ^^^^^^
Quoted 8 lines
Quoted 4 lines

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

I haven't observed this warning during my normal Linux build using gcc. Is there any specific configuration you are using?

It's from the Sparse tool.

regards,
dan carpenter

#11 lore raw
In reply to Wei Yongjun
Quoted 5 lines · Wei Yongjun

Fixes the following sparse warning:

drivers/char/hw_random/optee-rng.c:265:35: warning:
symbol 'optee_rng_id_table' was not declared. Should it be static?

Static limits visibility to the current translation unit. Static is like private visibility.

Maybe you are thinking if it should be declared extern so other translation units can find the symbol. extern is like public visibility.

Jeff