md: dm-writeback: add __noreturn to BUG-ging function
Subsystems (2)
PATCH 1/1 md: dm-writeback: add __noreturn to BUG-ging function
Building on arch/s390/ flags this as an error, so add the __noreturn attribute modifier to prevent the build error.
cc1: some warnings being treated as errors../drivers/md/dm-writecache.c: In function 'persistent_memory_claim':../drivers/md/dm-writecache.c:323:1: error: no return statement in function returning non-void [-Werror=return-type]
--- drivers/md/dm-writecache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-writecache.c +1 -1
@@ -317,7 +317,7 @@ err1: return r; }#else -static int persistent_memory_claim (struct dm_writecache *wc) +static int __noreturn persistent_memory_claim (struct dm_writecache *wc) {BUG (); }
Quoted 6 lines · Randy Dunlap
Building on
arch/s390/flags this as an error, so add the__noreturnattribute modifier to prevent the build error.cc1: some warnings being treated as errors
../drivers/md/dm-writecache.c: In function 'persistent_memory_claim':../drivers/md/dm-writecache.c:323:1: error: no return statement in function returning non-void [-Werror=return-type]
ok with me, but I am asking why
the unreachable macro is not good enough. For x86 it obviously is.
form arch/s390/include/asm/bug.h
#define BUG() do { \
__EMIT_BUG(0); \
unreachable(); \} while (0)
Quoted 27 lines
Fixes 48debafe4f2f ("dm: add writecache target")Signed-off-by Randy Dunlap <[email protected]>Cc Mikulas Patocka <[email protected]>Cc Alasdair Kergon <[email protected]>Cc Mike Snitzer <[email protected]>Cc Heiko Carstens <[email protected]>Cc Vasily Gorbik <[email protected]>Cc Christian Borntraeger <[email protected]>--- drivers/md/dm-writecache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/dm-writecache.c +1
-1@@ -317,7 +317,7 @@ err1: return r; }#else -static int persistent_memory_claim (struct dm_writecache *wc) +static int __noreturn persistent_memory_claim (struct dm_writecache *wc) {BUG (); }
Quoted 12 lines · Christian Borntraeger
Quoted 6 lines · Randy Dunlap
Building on
arch/s390/flags this as an error, so add the__noreturnattribute modifier to prevent the build error.cc1: some warnings being treated as errors
../drivers/md/dm-writecache.c: In function 'persistent_memory_claim':../drivers/md/dm-writecache.c:323:1: error: no return statement in function returning non-void [-Werror=return-type]ok with me, but I am asking why
Quoted 8 lines
the unreachable macro is not good enough. For x86 it obviously is.
form
arch/s390/include/asm/bug.h#define BUG() do { \ __EMIT_BUG(0); \ unreachable(); \} while (0)
Hi Christian,
Good question.
I don't see any guidance about when to use one or the other etc.
I see __noreturn being used 109 times and unreachable(); being used 33 times, but only now that I look at them. That had nothing to do with why I used __noreturn in the patch.
Quoted 16 lines
Quoted 16 lines
Fixes 48debafe4f2f ("dm: add writecache target")Signed-off-by Randy Dunlap <[email protected]>Cc Mikulas Patocka <[email protected]>Cc Alasdair Kergon <[email protected]>Cc Mike Snitzer <[email protected]>Cc Heiko Carstens <[email protected]>Cc Vasily Gorbik <[email protected]>Cc Christian Borntraeger <[email protected]>--- drivers/md/dm-writecache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines
drivers/md/dm-writecache.c err1: · line 323
Quoted 12 lines
drivers/md/dm-writecache.c +1
-1@@ -317,7 +317,7 @@ err1: return r; }#else -static int persistent_memory_claim (struct dm_writecache *wc) +static int __noreturn persistent_memory_claim (struct dm_writecache *wc) {BUG (); }
thanks.
Signature · 1 line
~Randy
Quoted 22 lines · Randy Dunlap
Quoted 12 lines · Christian Borntraeger
Quoted 6 lines · Randy Dunlap
Building on
arch/s390/flags this as an error, so add the__noreturnattribute modifier to prevent the build error.cc1: some warnings being treated as errors
../drivers/md/dm-writecache.c: In function 'persistent_memory_claim':../drivers/md/dm-writecache.c:323:1: error: no return statement in function returning non-void [-Werror=return-type]ok with me, but I am asking why
Quoted 8 lines
the unreachable macro is not good enough. For x86 it obviously is.
form
arch/s390/include/asm/bug.h#define BUG() do { \ __EMIT_BUG(0); \ unreachable(); \} while (0)
Quoted 8 lines
Hi Christian,
Good question.
I don't see any guidance about when to use one or the other etc.I see
__noreturnbeing used 109 times andunreachable(); being used 33 times, but only now that I look at them. That had nothing to do with why I used__noreturnin the patch.
But doesn't that speak to the proper fix being needed in unreachable()? Or at a minimum the fix is needed to arch/s390/include/asm/bug.h's BUG.
I really don't think we should be papering over that by sprinkling __noreturn around the kernel's BUG() callers.
Maybe switch arch/s390/include/asm/bug.h's BUG to be like arch/mips/include/asm/bug.h? It itself uses __noreturn with a 'static inline' function definition rather than #define.
Does that fix the issue?
Thanks,
Mike
p.s. you modified dm-writecache.c (not dm-writeback, wich doesn't exist).
Quoted 44 lines · Mike Snitzer
Quoted 22 lines · Randy Dunlap
Quoted 12 lines · Christian Borntraeger
Quoted 6 lines · Randy Dunlap
Building on
arch/s390/flags this as an error, so add the__noreturnattribute modifier to prevent the build error.cc1: some warnings being treated as errors
../drivers/md/dm-writecache.c: In function 'persistent_memory_claim':../drivers/md/dm-writecache.c:323:1: error: no return statement in function returning non-void [-Werror=return-type]ok with me, but I am asking why
Quoted 8 lines
the unreachable macro is not good enough. For x86 it obviously is.
form
arch/s390/include/asm/bug.h#define BUG() do { \ __EMIT_BUG(0); \ unreachable(); \} while (0)
Quoted 8 lines
Hi Christian,
Good question.
I don't see any guidance about when to use one or the other etc.I see
__noreturnbeing used 109 times andunreachable(); being used 33 times, but only now that I look at them. That had nothing to do with why I used__noreturnin the patch.But doesn't that speak to the proper fix being needed in
unreachable()? Or at a minimum the fix is needed to arch/s390/include/asm/bug.h's BUG.I really don't think we should be papering over that by sprinkling
__noreturnaround the kernel'sBUG()callers.Maybe switch arch/s390/include/asm/bug.h's BUG to be like
arch/mips/include/asm/bug.h? It itself uses__noreturnwith a 'static inline' function definition rather than #define.
Quoted 7 lines
Does that fix the issue?
Thanks,
Mikep.s. you modified
dm-writecache.c(not dm-writeback, wich doesn't exist).
I don't think my suggestion will help.. given it'd still leave persistent_memory_claim() without a return statement.
Think it worthwhile to just add a dummy 'return 0;' after the BUG().
Mike
Quoted 4 lines · Mike Snitzer
I don't think my suggestion will help.. given it'd still leave
persistent_memory_claim()without a return statement.Think it worthwhile to just add a dummy 'return 0;' after the
BUG().
Decided to go with this, now staged for 5.11:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-5.11&id=a1e4865b4dda7071f3707f7e551289ead66e38b1
Quoted 11 lines · Mike Snitzer
Quoted 4 lines · Mike Snitzer
I don't think my suggestion will help.. given it'd still leave
persistent_memory_claim()without a return statement.Think it worthwhile to just add a dummy 'return 0;' after the
BUG().Decided to go with this, now staged for 5.11:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-5.11&id=a1e4865b4dda7071f3707f7e551289ead66e38b1
Looks like a sane solution. Thank you for following up.
Quoted 9 lines · Christian Borntraeger
Quoted 6 lines · Mike Snitzer
Quoted 3 lines · Mike Snitzer
I don't think my suggestion will help.. given it'd still leave
persistent_memory_claim()without a return statement.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Think it worthwhile to just add a dummy 'return 0;' after the
BUG().Decided to go with this, now staged for 5.11:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-5.11&id=a1e4865b4dda7071f3707f7e551289ead66e38b1Looks like a sane solution. Thank you for following up.
Yes, thanks again.
Signature · 1 line
~Randy
Mikulas Patocka
maintainerQuoted 10 lines · Mike Snitzer
Quoted 4 lines · Mike Snitzer
I don't think my suggestion will help.. given it'd still leave
persistent_memory_claim()without a return statement.Think it worthwhile to just add a dummy 'return 0;' after the
BUG().Decided to go with this, now staged for 5.11:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-5.11&id=a1e4865b4dda7071f3707f7e551289ead66e38b1
Hi
I would just use "return -EOPNOTSUPP;" and drop the "#ifdef DM_WRITECACHE_HAS_PMEM" that you added.
That BUG/return -EOPNOTSUPP code can't happen at all - if DM_WRITECACHE_HAS_PMEM is not defined, WC_MODE_PMEM(wc) always returns false - so persistent_memory_claim and BUG() can't ever be called. And if it can't be called, you don't need to add a code that prints an error in that case.
If we don't have DM_WRITECACHE_HAS_PMEM, the compiler optimizer will remove all the code guarded with if (WC_MODE_PMEM(wc)) as unreachable.
Mikulas
From: Mikulas Patocka <[email protected]>
Subject: [PATCH] dm writecache: remove BUG() and fail gracefully insteadfor-nextdm-5.11
Building on arch/s390/ results in this build error:
cc1: some warnings being treated as errors../drivers/md/dm-writecache.c: In function 'persistent_memory_claim':../drivers/md/dm-writecache.c:323:1: error: no return statement in function returning non-void [-Werror=return-type]
Fix this by replacing the BUG() with a -EOPNOTSUPP return.
drivers/md/dm-writecache.c +1 -1
@@ -319,7 +319,7 @@ err1:#else static int persistent_memory_claim (struct dm_writecache *wc) { -BUG (); +return -EOPNOTSUPP ; }#endif
Quoted 26 lines · Mikulas Patocka
Quoted 10 lines · Mike Snitzer
Quoted 4 lines · Mike Snitzer
I don't think my suggestion will help.. given it'd still leave
persistent_memory_claim()without a return statement.Think it worthwhile to just add a dummy 'return 0;' after the
BUG().Decided to go with this, now staged for 5.11:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-5.11&id=a1e4865b4dda7071f3707f7e551289ead66e38b1Hi
I would just use "return
-EOPNOTSUPP;" and drop the "#ifdefDM_WRITECACHE_HAS_PMEM" that you added.That BUG/return
-EOPNOTSUPPcode can't happen at all - ifDM_WRITECACHE_HAS_PMEMis not defined,WC_MODE_PMEM(wc)always returns false - sopersistent_memory_claimandBUG()can't ever be called. And if it can't be called, you don't need to add a code that prints an error in that case.
Quoted 4 lines
If we don't have
DM_WRITECACHE_HAS_PMEM, the compiler optimizer will remove all the code guarded with if (WC_MODE_PMEM(wc)) as unreachable.Mikulas
Fair enough.