staging: vt6655: device_main: switch multiple assignment for one assignment per line
PATCH 1/1 staging: vt6655: device_main: switch multiple assignment for one assignment per line
One assignment per line is preferred, instead of multiple assignments. To prevent possible undefined behavior.
Issue found with checkpath.
--- drivers/staging/vt6655/device_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/vt6655/device_main.c +2 -1
@@ -708,7 +708,8 @@ static int device_init_td1_ring(struct vnt_private *priv)if (i >0 ) priv->apTD1Rings[i -1 ].next_desc =cpu_to_le32 (priv->td1_pool_dma); - priv->apTailTD[1 ] = priv->apCurrTD[1 ] = &priv->apTD1Rings[0 ]; + priv->apCurrTD[1 ] = &priv->apTD1Rings[0 ]; + priv->apTailTD[1 ] = &priv->apTD1Rings[0 ];return 0 ;
Signature · 1 line
2.17.1
Quoted 2 lines · Lourdes Pedrajas
One assignment per line is preferred, instead of multiple assignments. To prevent possible undefined behavior.
There is no possible undefined behavior. The C semantics provides a definition of what this means. On the other hand, people don't seem to be so familiar with what this semantics is. Looking quickly with Google, I find some pages that think that it is the value of the left side expression and some pages that this that it is the value of the right side expression. This can have an impact if the types are different and the assignment involves an implicit cast. Here all the types are the same.
I'm not really sure which would be preferred. The original code is a bit more concise. The modified code is a bit more clear, because one can find what is assigned by just looking in one standard place, ie the left side of the code.
Quoted 1 line
Issue found with checkpath.
checkpatch :)
julia
Quoted 28 lines
Signed-off-by Lourdes Pedrajas <[email protected]>--- drivers/staging/vt6655/device_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/staging/vt6655/device_main.c +2
-2@@ -708,7 +708,8 @@ static int device_init_td1_ring(struct vnt_private *priv)if (i >0 ) priv->apTD1Rings[i -1 ].next_desc =cpu_to_le32 (priv->td1_pool_dma); - priv->apTailTD[1 ] = priv->apCurrTD[1 ] = &priv->apTD1Rings[0 ]; + priv->apCurrTD[1 ] = &priv->apTD1Rings[0 ]; + priv->apTailTD[1 ] = &priv->apTD1Rings[0 ];return 0 ; --2.17.1
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20200315044620.14104-1-lu%40pplo.net.
Quoted 20 lines · Julia Lawall
Quoted 2 lines · Lourdes Pedrajas
One assignment per line is preferred, instead of multiple assignments. To prevent possible undefined behavior.
There is no possible undefined behavior. The C semantics provides a definition of what this means. On the other hand, people don't seem to be so familiar with what this semantics is. Looking quickly with Google, I find some pages that think that it is the value of the left side expression and some pages that this that it is the value of the right side expression. This can have an impact if the types are different and the assignment involves an implicit cast. Here all the types are the same.
I'm not really sure which would be preferred. The original code is a bit more concise. The modified code is a bit more clear, because one can find what is assigned by just looking in one standard place, ie the left side of the code.
Quoted 6 lines
Quoted 1 line
Issue found with checkpath.
checkpatch :)
julia
I also was unsure if it was undefined behavior as checkpatch says, it assign 3rd value to 2nd, and then to 1st, to me is clear.
The change may make the code more readable and would help people that is not familiar with multiple assignments.
If the maintainer agree, I will simply correct the typo in checkpatch :)
Thank you Julia!
Lourdes
Greg KH
maintainerQuoted 14 lines · Lourdes Pedrajas
One assignment per line is preferred, instead of multiple assignments. To prevent possible undefined behavior.
Issue found with checkpath.Signed-off-by Lourdes Pedrajas <[email protected]>--- drivers/staging/vt6655/device_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/staging/vt6655/device_main.c +0
-0
drivers/staging/vt6655/device_main.c static int device_init_td1_ring(struct vnt_private *priv) · line 712
Quoted 6 lines
drivers/staging/vt6655/device_main.c +2
-1@@ -708,7 +708,8 @@ static int device_init_td1_ring(struct vnt_private *priv)if (i >0 ) priv->apTD1Rings[i -1 ].next_desc =cpu_to_le32 (priv->td1_pool_dma); - priv->apTailTD[1 ] = priv->apCurrTD[1 ] = &priv->apTD1Rings[0 ]; + priv->apCurrTD[1 ] = &priv->apTD1Rings[0 ]; + priv->apTailTD[1 ] = &priv->apTD1Rings[0 ];
As others said here, there is no undefined behavior, the original code is just fine.
thanks,
greg k-h
Quoted 25 lines · Greg KH
Quoted 14 lines · Lourdes Pedrajas
One assignment per line is preferred, instead of multiple assignments. To prevent possible undefined behavior.
Issue found with checkpath.Signed-off-by Lourdes Pedrajas <[email protected]>--- drivers/staging/vt6655/device_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/staging/vt6655/device_main.c +0
-0drivers/staging/vt6655/device_main.c static int device_init_td1_ring(struct vnt_private *priv) · line 712
Quoted 6 lines
drivers/staging/vt6655/device_main.c +2
-1@@ -708,7 +708,8 @@ static int device_init_td1_ring(struct vnt_private *priv)if (i >0 ) priv->apTD1Rings[i -1 ].next_desc =cpu_to_le32 (priv->td1_pool_dma); - priv->apTailTD[1 ] = priv->apCurrTD[1 ] = &priv->apTD1Rings[0 ]; + priv->apCurrTD[1 ] = &priv->apTD1Rings[0 ]; + priv->apTailTD[1 ] = &priv->apTD1Rings[0 ];As others said here, there is no undefined behavior, the original code is just fine.
Quoted 3 lines
thanks,
greg k-h
I agree, thank you,
Lourdes