tee: optee: Initialize some structs using memset instead of braces
Subsystems (2)
PATCH 1/1 tee: optee: Initialize some structs using memset instead of braces
Clang warns:
drivers/tee/optee/device.c:39:31: warning: suggest braces around initialization of subobject [-Wmissing-braces]
struct tee_param param[4] = {0};
^
{}
drivers/tee/optee/device.c:92:48: warning: suggest braces around
initialization of subobject [-Wmissing-braces]
struct tee_ioctl_open_session_arg sess_arg = {0};
^
{}2 warnings generated.
One way to fix these warnings is to add additional braces like Clang suggests; however, there has been a bit of push back from some maintainers, who just prefer memset as it is unambiguous, doesn't depend on a particular compiler version, and properly initializes all subobjects [1][2]. Do that here so there are no more warnings.
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
--- drivers/tee/optee/device.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/tee/optee/device.c +8 -3
@@ -35,8 +35,11 @@ static int get_devices(struct tee_context *ctx, u32 session, struct tee_shm *device_shm, u32 *shm_size) { u32 ret = 0; -struct tee_ioctl_invoke_arg inv_arg = {0 }; -struct tee_param param[4 ] = {0 }; +struct tee_ioctl_invoke_arg inv_arg; +struct tee_param param[4 ]; + +memset (&inv_arg,0 ,sizeof (inv_arg)); +memset (¶m,0 ,sizeof (param));/* Invoke PTA_CMD_GET_DEVICES function */ inv_arg.func =PTA_CMD_GET_DEVICES ;
@@ -89,13 +92,15 @@ int optee_enumerate_devices(void)const uuid_t pta_uuid =UUID_INIT (0x7011a688 ,0xddde ,0x4053 ,0xa5 ,0xa9 ,0x7b ,0x3c ,0x4d ,0xdf ,0x13 ,0xb8 ); -struct tee_ioctl_open_session_arg sess_arg = {0 }; +struct tee_ioctl_open_session_arg sess_arg;struct tee_shm *device_shm =NULL ;const uuid_t *device_uuid =NULL ;struct tee_context *ctx =NULL ;u32 shm_size =0 , idx, num_devices =0 ;int rc; +memset (&sess_arg,0 ,sizeof (sess_arg)); +/* Open context with OP-TEE driver */ ctx =tee_client_open_context (NULL , optee_ctx_match,NULL ,NULL );if (IS_ERR (ctx))
Signature · 1 line
2.21.0.rc1
Quoted 21 lines · Nathan Chancellor
Clang warns:
drivers/tee/optee/device.c:39:31: warning: suggest braces around initialization of subobject [-Wmissing-braces]struct tee_param param[4] = {0}; ^ {} drivers/tee/optee/device.c:92:48: warning: suggest braces around initialization of subobject [-Wmissing-braces] struct tee_ioctl_open_session_arg sess_arg = {0}; ^ {}2 warnings generated.
One way to fix these warnings is to add additional braces like Clang suggests; however, there has been a bit of push back from some maintainers, who just prefer memset as it is unambiguous, doesn't depend on a particular compiler version, and properly initializes all subobjects [1][2]. Do that here so there are no more warnings.
Quoted 6 lines
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/Fixes c3fa24af9244 ("tee: optee: add TEE bus device enumeration support")Signed-off-by Nathan Chancellor <[email protected]>
Quoted 42 lines
--- drivers/tee/optee/device.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/tee/optee/device.c +8
-4@@ -35,8 +35,11 @@ static int get_devices(struct tee_context *ctx, u32 session, struct tee_shm *device_shm, u32 *shm_size) { u32 ret = 0; -struct tee_ioctl_invoke_arg inv_arg = {0 }; -struct tee_param param[4 ] = {0 }; +struct tee_ioctl_invoke_arg inv_arg; +struct tee_param param[4 ]; + +memset (&inv_arg,0 ,sizeof (inv_arg)); +memset (¶m,0 ,sizeof (param));/* Invoke PTA_CMD_GET_DEVICES function */ inv_arg.func =PTA_CMD_GET_DEVICES ;@@ -89,13 +92,15 @@ int optee_enumerate_devices(void)const uuid_t pta_uuid =UUID_INIT (0x7011a688 ,0xddde ,0x4053 ,0xa5 ,0xa9 ,0x7b ,0x3c ,0x4d ,0xdf ,0x13 ,0xb8 ); -struct tee_ioctl_open_session_arg sess_arg = {0 }; +struct tee_ioctl_open_session_arg sess_arg;struct tee_shm *device_shm =NULL ;const uuid_t *device_uuid =NULL ;struct tee_context *ctx =NULL ;u32 shm_size =0 , idx, num_devices =0 ;int rc; +memset (&sess_arg,0 ,sizeof (sess_arg)); +/* Open context with OP-TEE driver */ ctx =tee_client_open_context (NULL , optee_ctx_match,NULL ,NULL );if (IS_ERR (ctx)) --2.21.0.rc1
Quoted 8 lines · Sumit Garg
Quoted 4 lines · Nathan Chancellor
Fixes c3fa24af9244 ("tee: optee: add TEE bus device enumeration support")Signed-off-by Nathan Chancellor <[email protected]>Reviewed-by Sumit Garg <[email protected]>
I independently noticed the same bug, so I went ahead and applied Nathan's fix with your Reviewed-by tag into the arm/drivers tree.
Arnd