]> git.baikalelectronics.ru Git - kernel.git/commit
sysrq: don't depend on weak undefined arrays to have an address that compares as...
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 27 Feb 2013 17:59:50 +0000 (09:59 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 27 Feb 2013 17:59:50 +0000 (09:59 -0800)
commit0976daaaeaba5448e907c2d4d3343e405b016f28
tree36b32a7daaad132c66d7e2d09e922a85d1e2ac5b
parent5a634391b96956a01ed0d0803257e584a1487677
sysrq: don't depend on weak undefined arrays to have an address that compares as NULL

When taking an address of an extern array, gcc quite naturally should be
able to say "an address of an object can never be NULL" and just
optimize away the test entirely.

However, the new alternate sysrq reset code (commit 4cb968c365f2:
"Input: sysrq - allow specifying alternate reset sequence") did exactly
that, and declared platform_sysrq_reset_seq[] as a weak array, and
expecting that testing the address of the array would show whether it
actually got linked against something or not.

And that doesn't work with all gcc versions.  Clearly it works with
*some* versions of gcc, and maybe it's even supposed to work, but it
really is a very fragile concept.

So instead of testing the address of the weak variable, just create a
weak instance of that array that is empty.  If some platform then has a
real platform_sysrq_reset_seq[] that overrides our weak one, the linker
will switch to that one, and it all works without any run-time
conditionals at all.

Reported-by: Dave Airlie <airlied@gmail.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/tty/sysrq.c