dma-buf: st: fix error handling in test_get_fences()
Subsystems (2)
PATCH 1/1 dma-buf: st: fix error handling in test_get_fences()
From: Arnd Bergmann <[email protected]>
The new driver incorrectly unwinds after errors, as clang points out:
drivers/dma-buf/st-dma-resv.c:295:7: error: variable 'i' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (r) {
^
drivers/dma-buf/st-dma-resv.c:336:9: note: uninitialized use occurs here
while (i--)
^
drivers/dma-buf/st-dma-resv.c:295:3: note: remove the 'if' if its condition is always false
if (r) {
^~~~~~~~
drivers/dma-buf/st-dma-resv.c:288:6: error: variable 'i' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (r) {
^
drivers/dma-buf/st-dma-resv.c:336:9: note: uninitialized use occurs here
while (i--)
^
drivers/dma-buf/st-dma-resv.c:288:2: note: remove the 'if' if its condition is always false
if (r) {
^~~~~~~~
drivers/dma-buf/st-dma-resv.c:280:10: note: initialize the variable 'i' to silence this warning
int r, i;
^
= 0Skip cleaning up the bits that have not been allocated at this point.
---
I'm not familiar with these interfaces, so I'm just guessing where we should jump after an error, please double-check and fix if necessary.
--- drivers/dma-buf/st-dma-resv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dma-buf/st-dma-resv.c +3 -2
@@ -287,7 +287,7 @@ static int test_get_fences(void *arg, bool shared) r =dma_resv_lock (&resv,NULL );if (r) {pr_err ("Resv locking failed\n" ); - goto err_free; + goto err_resv; }if (shared) {
@@ -295,7 +295,7 @@ static int test_get_fences(void *arg, bool shared)if (r) {pr_err ("Resv shared slot allocation failed\n" );dma_resv_unlock (&resv); - goto err_free; + goto err_resv; }dma_resv_add_shared_fence (&resv, f);
@@ -336,6 +336,7 @@ static int test_get_fences(void *arg, bool shared)while (i--)dma_fence_put (fences[i]);kfree (fences); +err_resv:dma_resv_fini (&resv);dma_fence_put (f);return r;
Signature · 1 line
2.29.2
Christian König
maintainerAm 26.10.21 um 10:34 schrieb Arnd Bergmann:
Quoted 27 lines
From: Arnd Bergmann <[email protected]>
The new driver incorrectly unwinds after errors, as clang points out:
drivers/dma-buf/st-dma-resv.c:295:7: error: variable 'i' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]if (r) { ^ drivers/dma-buf/st-dma-resv.c:336:9: note: uninitialized use occurs here while (i--) ^ drivers/dma-buf/st-dma-resv.c:295:3: note: remove the 'if' if its condition is always false if (r) { ^~~~~~~~ drivers/dma-buf/st-dma-resv.c:288:6: error: variable 'i' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (r) { ^ drivers/dma-buf/st-dma-resv.c:336:9: note: uninitialized use occurs here while (i--) ^ drivers/dma-buf/st-dma-resv.c:288:2: note: remove the 'if' if its condition is always false if (r) { ^~~~~~~~ drivers/dma-buf/st-dma-resv.c:280:10: note: initialize the variable 'i' to silence this warning int r, i; ^ = 0
Quoted 4 lines
Skip cleaning up the bits that have not been allocated at this point.
Fixes 1d51775cd3f5 ("dma-buf: add dma_resv selftest v4")Signed-off-by Arnd Bergmann <[email protected]>
I already send out a patch to fix this up, but forgot to fix both gotos.
Going to add my rb and using that one here instead.
Thanks,
Christian.
Quoted 37 lines
---
I'm not familiar with these interfaces, so I'm just guessing where we should jump after an error, please double-check and fix if necessary.--- drivers/dma-buf/st-dma-resv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/dma-buf/st-dma-resv.c +3
-2@@ -287,7 +287,7 @@ static int test_get_fences(void *arg, bool shared) r =dma_resv_lock (&resv,NULL );if (r) {pr_err ("Resv locking failed\n" ); - goto err_free; + goto err_resv; }if (shared) {@@ -295,7 +295,7 @@ static int test_get_fences(void *arg, bool shared)if (r) {pr_err ("Resv shared slot allocation failed\n" );dma_resv_unlock (&resv); - goto err_free; + goto err_resv; }dma_resv_add_shared_fence (&resv, f);@@ -336,6 +336,7 @@ static int test_get_fences(void *arg, bool shared)while (i--)dma_fence_put (fences[i]);kfree (fences); +err_resv:dma_resv_fini (&resv);dma_fence_put (f);return r;
Quoted 27 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The new driver incorrectly unwinds after errors, as clang points out:
drivers/dma-buf/st-dma-resv.c:295:7: error: variable 'i' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]if (r) { ^ drivers/dma-buf/st-dma-resv.c:336:9: note: uninitialized use occurs here while (i--) ^ drivers/dma-buf/st-dma-resv.c:295:3: note: remove the 'if' if its condition is always false if (r) { ^~~~~~~~ drivers/dma-buf/st-dma-resv.c:288:6: error: variable 'i' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (r) { ^ drivers/dma-buf/st-dma-resv.c:336:9: note: uninitialized use occurs here while (i--) ^ drivers/dma-buf/st-dma-resv.c:288:2: note: remove the 'if' if its condition is always false if (r) { ^~~~~~~~ drivers/dma-buf/st-dma-resv.c:280:10: note: initialize the variable 'i' to silence this warning int r, i; ^ = 0
Quoted 4 lines
Skip cleaning up the bits that have not been allocated at this point.
Fixes 1d51775cd3f5 ("dma-buf: add dma_resv selftest v4")Signed-off-by Arnd Bergmann <[email protected]>
Quoted 40 lines
---
I'm not familiar with these interfaces, so I'm just guessing where we should jump after an error, please double-check and fix if necessary.--- drivers/dma-buf/st-dma-resv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/dma-buf/st-dma-resv.c +3
-2@@ -287,7 +287,7 @@ static int test_get_fences(void *arg, bool shared) r =dma_resv_lock (&resv,NULL );if (r) {pr_err ("Resv locking failed\n" ); - goto err_free; + goto err_resv; }if (shared) {@@ -295,7 +295,7 @@ static int test_get_fences(void *arg, bool shared)if (r) {pr_err ("Resv shared slot allocation failed\n" );dma_resv_unlock (&resv); - goto err_free; + goto err_resv; }dma_resv_add_shared_fence (&resv, f);@@ -336,6 +336,7 @@ static int test_get_fences(void *arg, bool shared)while (i--)dma_fence_put (fences[i]);kfree (fences); +err_resv:dma_resv_fini (&resv);dma_fence_put (f);return r;Signature · 1 line
2.29.2