* [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI
@ 2014-02-12 20:58 dl9pf
2014-02-12 21:11 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: dl9pf @ 2014-02-12 20:58 UTC (permalink / raw)
To: dl9pf
Cc: Behan Webster, David Woodhouse, Matthew Garrett, ibm-acpi-devel,
platform-driver-x86, linux-kernel
From: Behan Webster <behanw@converseincode.com>
The only real change is passing in event_mask to the formerly nested functions.
Otherwise it's just moving around function and macro code.
This is the only place in the Linux kernel where nested functions are still in
use. Nested functions aren't part of the C standards, and complicate the
generated code. Although the Linux Kernel has never set out to be entirely C
standard compliant, it is increasingly compliant to the standard which is
supported by other compilers such as Clang. The LLVMLinux project is working on
being able to compile the Linux kernel with Clang. The use of nested functions
blocks this effort.
Signed-off-by: Behan Webster <behanw@converseincode.com>
Signed-off-by: Jan-Simon Möller <dl9pf@gmx.de>
CC: David Woodhouse <David.Woodhouse@intel.com>
CC: Matthew Garrett <matthew.garrett@nebula.com>
CC: ibm-acpi-devel@lists.sourceforge.net
CC: platform-driver-x86@vger.kernel.org
CC: linux-kernel@vger.kernel.org
---
drivers/platform/x86/thinkpad_acpi.c | 86 +++++++++++++++++++-----------------
1 file changed, 45 insertions(+), 41 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index defb6af..e6e068e 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2321,53 +2321,55 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
}
}
-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
- struct tp_nvram_state *newn,
- const u32 event_mask)
-{
-
#define TPACPI_COMPARE_KEY(__scancode, __member) \
- do { \
- if ((event_mask & (1 << __scancode)) && \
- oldn->__member != newn->__member) \
- tpacpi_hotkey_send_key(__scancode); \
- } while (0)
+do { \
+ if ((event_mask & (1 << __scancode)) && \
+ oldn->__member != newn->__member) \
+ tpacpi_hotkey_send_key(__scancode); \
+} while (0)
#define TPACPI_MAY_SEND_KEY(__scancode) \
- do { \
- if (event_mask & (1 << __scancode)) \
- tpacpi_hotkey_send_key(__scancode); \
- } while (0)
+do { \
+ if (event_mask & (1 << __scancode)) \
+ tpacpi_hotkey_send_key(__scancode); \
+} while (0)
- void issue_volchange(const unsigned int oldvol,
- const unsigned int newvol)
- {
- unsigned int i = oldvol;
+static void issue_volchange(const unsigned int oldvol,
+ const unsigned int newvol,
+ const u32 event_mask)
+{
+ unsigned int i = oldvol;
- while (i > newvol) {
- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
- i--;
- }
- while (i < newvol) {
- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
- i++;
- }
+ while (i > newvol) {
+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
+ i--;
+ }
+ while (i < newvol) {
+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
+ i++;
}
+}
- void issue_brightnesschange(const unsigned int oldbrt,
- const unsigned int newbrt)
- {
- unsigned int i = oldbrt;
+static void issue_brightnesschange(const unsigned int oldbrt,
+ const unsigned int newbrt,
+ const u32 event_mask)
+{
+ unsigned int i = oldbrt;
- while (i > newbrt) {
- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
- i--;
- }
- while (i < newbrt) {
- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
- i++;
- }
+ while (i > newbrt) {
+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
+ i--;
}
+ while (i < newbrt) {
+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
+ i++;
+ }
+}
+
+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
+ struct tp_nvram_state *newn,
+ const u32 event_mask)
+{
TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
@@ -2402,7 +2404,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
oldn->volume_level != newn->volume_level) {
/* recently muted, or repeated mute keypress, or
* multiple presses ending in mute */
- issue_volchange(oldn->volume_level, newn->volume_level);
+ issue_volchange(oldn->volume_level, newn->volume_level,
+ event_mask);
TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
}
} else {
@@ -2412,7 +2415,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
}
if (oldn->volume_level != newn->volume_level) {
- issue_volchange(oldn->volume_level, newn->volume_level);
+ issue_volchange(oldn->volume_level, newn->volume_level,
+ event_mask);
} else if (oldn->volume_toggle != newn->volume_toggle) {
/* repeated vol up/down keypress at end of scale ? */
if (newn->volume_level == 0)
@@ -2425,7 +2429,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
/* handle brightness */
if (oldn->brightness_level != newn->brightness_level) {
issue_brightnesschange(oldn->brightness_level,
- newn->brightness_level);
+ newn->brightness_level, event_mask);
} else if (oldn->brightness_toggle != newn->brightness_toggle) {
/* repeated key presses that didn't change state */
if (newn->brightness_level == 0)
--
1.8.4.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI
2014-02-12 20:58 [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI dl9pf
@ 2014-02-12 21:11 ` Christoph Hellwig
2014-02-12 21:20 ` Behan Webster
2014-02-12 21:54 ` David Rientjes
2014-02-13 13:03 ` Henrique de Moraes Holschuh
2 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2014-02-12 21:11 UTC (permalink / raw)
To: dl9pf
Cc: Behan Webster, David Woodhouse, Matthew Garrett, ibm-acpi-devel,
platform-driver-x86, linux-kernel
On Wed, Feb 12, 2014 at 09:58:46PM +0100, dl9pf@gmx.de wrote:
> being able to compile the Linux kernel with Clang. The use of nested functions
> blocks this effort.
Is there any good way to make gcc warn about the use of nested functions?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI
2014-02-12 21:11 ` Christoph Hellwig
@ 2014-02-12 21:20 ` Behan Webster
2014-02-12 21:27 ` Måns Rullgård
2014-02-12 21:32 ` Richard Weinberger
0 siblings, 2 replies; 8+ messages in thread
From: Behan Webster @ 2014-02-12 21:20 UTC (permalink / raw)
To: Christoph Hellwig, dl9pf
Cc: David Woodhouse, Matthew Garrett, ibm-acpi-devel,
platform-driver-x86, linux-kernel
On 02/12/14 13:11, Christoph Hellwig wrote:
> On Wed, Feb 12, 2014 at 09:58:46PM +0100, dl9pf@gmx.de wrote:
>> being able to compile the Linux kernel with Clang. The use of nested functions
>> blocks this effort.
> Is there any good way to make gcc warn about the use of nested functions?
Interesting idea.
'-Wtrampolines'
Warn about trampolines generated for pointers to nested functions.
A trampoline is a small piece of data or code that is created at
run time on the stack when the address of a nested function is
taken, and is used to call the nested function indirectly. For
some targets, it is made up of data only and thus requires no
special treatment. But, for most targets, it is made up of code
and thus requires the stack to be made executable in order for the
program to work properly.
That might work.
Behan
--
Behan Webster
behanw@converseincode.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI
2014-02-12 21:20 ` Behan Webster
@ 2014-02-12 21:27 ` Måns Rullgård
2014-02-12 21:32 ` Richard Weinberger
1 sibling, 0 replies; 8+ messages in thread
From: Måns Rullgård @ 2014-02-12 21:27 UTC (permalink / raw)
To: Behan Webster
Cc: Christoph Hellwig, dl9pf, David Woodhouse, Matthew Garrett,
ibm-acpi-devel, platform-driver-x86, linux-kernel
Behan Webster <behanw@converseincode.com> writes:
> On 02/12/14 13:11, Christoph Hellwig wrote:
>> On Wed, Feb 12, 2014 at 09:58:46PM +0100, dl9pf@gmx.de wrote:
>>> being able to compile the Linux kernel with Clang. The use of nested functions
>>> blocks this effort.
>> Is there any good way to make gcc warn about the use of nested functions?
> Interesting idea.
>
> '-Wtrampolines'
> Warn about trampolines generated for pointers to nested functions.
>
> A trampoline is a small piece of data or code that is created at
> run time on the stack when the address of a nested function is
> taken, and is used to call the nested function indirectly. For
> some targets, it is made up of data only and thus requires no
> special treatment. But, for most targets, it is made up of code
> and thus requires the stack to be made executable in order for the
> program to work properly.
>
> That might work.
That sounds like it will only warn if a trampoline is needed. A nested
function whose address isn't taken, as is the case here, wouldn't
trigger this warning.
--
Måns Rullgård
mans@mansr.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI
2014-02-12 21:20 ` Behan Webster
2014-02-12 21:27 ` Måns Rullgård
@ 2014-02-12 21:32 ` Richard Weinberger
1 sibling, 0 replies; 8+ messages in thread
From: Richard Weinberger @ 2014-02-12 21:32 UTC (permalink / raw)
To: Behan Webster
Cc: Christoph Hellwig, dl9pf, David Woodhouse, Matthew Garrett,
ibm-acpi-devel, platform-driver-x86, LKML
On Wed, Feb 12, 2014 at 10:20 PM, Behan Webster
<behanw@converseincode.com> wrote:
> On 02/12/14 13:11, Christoph Hellwig wrote:
>>
>> On Wed, Feb 12, 2014 at 09:58:46PM +0100, dl9pf@gmx.de wrote:
>>>
>>> being able to compile the Linux kernel with Clang. The use of nested
>>> functions
>>> blocks this effort.
>>
>> Is there any good way to make gcc warn about the use of nested functions?
>
> Interesting idea.
>
> '-Wtrampolines'
> Warn about trampolines generated for pointers to nested functions.
>
> A trampoline is a small piece of data or code that is created at
> run time on the stack when the address of a nested function is
> taken, and is used to call the nested function indirectly. For
> some targets, it is made up of data only and thus requires no
> special treatment. But, for most targets, it is made up of code
> and thus requires the stack to be made executable in order for the
> program to work properly.
>
>
> That might work.
I gave it a quick try, but gcc (4.7) did not bark.
--
Thanks,
//richard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI
2014-02-12 20:58 [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI dl9pf
2014-02-12 21:11 ` Christoph Hellwig
@ 2014-02-12 21:54 ` David Rientjes
2014-02-12 22:01 ` Al Viro
2014-02-13 13:03 ` Henrique de Moraes Holschuh
2 siblings, 1 reply; 8+ messages in thread
From: David Rientjes @ 2014-02-12 21:54 UTC (permalink / raw)
To: dl9pf
Cc: Behan Webster, David Woodhouse, Matthew Garrett, ibm-acpi-devel,
platform-driver-x86, linux-kernel
On Wed, 12 Feb 2014, dl9pf@gmx.de wrote:
> From: Behan Webster <behanw@converseincode.com>
>
> The only real change is passing in event_mask to the formerly nested functions.
> Otherwise it's just moving around function and macro code.
>
> This is the only place in the Linux kernel where nested functions are still in
> use. Nested functions aren't part of the C standards, and complicate the
> generated code. Although the Linux Kernel has never set out to be entirely C
> standard compliant, it is increasingly compliant to the standard which is
> supported by other compilers such as Clang. The LLVMLinux project is working on
> being able to compile the Linux kernel with Clang. The use of nested functions
> blocks this effort.
>
So this patch is only as a courtesy to clang and you're not complaining
about things like __builtin() functions, typeof, or a ? : b conditional
operators because clang happens to support them?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI
2014-02-12 21:54 ` David Rientjes
@ 2014-02-12 22:01 ` Al Viro
0 siblings, 0 replies; 8+ messages in thread
From: Al Viro @ 2014-02-12 22:01 UTC (permalink / raw)
To: David Rientjes
Cc: dl9pf, Behan Webster, David Woodhouse, Matthew Garrett,
ibm-acpi-devel, platform-driver-x86, linux-kernel
On Wed, Feb 12, 2014 at 01:54:43PM -0800, David Rientjes wrote:
> So this patch is only as a courtesy to clang and you're not complaining
> about things like __builtin() functions, typeof, or a ? : b conditional
> operators because clang happens to support them?
That patch removes a disgusting construct; who cares how they'd discovered
it? Consider it courtesy to reviewers, clang or no clang...
Folks, it's C; no need to bring Pascal misfeatures in, even if gcc happens
to accept them.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI
2014-02-12 20:58 [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI dl9pf
2014-02-12 21:11 ` Christoph Hellwig
2014-02-12 21:54 ` David Rientjes
@ 2014-02-13 13:03 ` Henrique de Moraes Holschuh
2 siblings, 0 replies; 8+ messages in thread
From: Henrique de Moraes Holschuh @ 2014-02-13 13:03 UTC (permalink / raw)
To: dl9pf
Cc: Behan Webster, David Woodhouse, Matthew Garrett, ibm-acpi-devel,
platform-driver-x86, linux-kernel
On Wed, 12 Feb 2014, dl9pf@gmx.de wrote:
> From: Behan Webster <behanw@converseincode.com>
> The only real change is passing in event_mask to the formerly nested functions.
> Otherwise it's just moving around function and macro code.
>
> This is the only place in the Linux kernel where nested functions are still in
> use. Nested functions aren't part of the C standards, and complicate the
> generated code. Although the Linux Kernel has never set out to be entirely C
> standard compliant, it is increasingly compliant to the standard which is
> supported by other compilers such as Clang. The LLVMLinux project is working on
> being able to compile the Linux kernel with Clang. The use of nested functions
> blocks this effort.
>
> Signed-off-by: Behan Webster <behanw@converseincode.com>
> Signed-off-by: Jan-Simon Möller <dl9pf@gmx.de>
>
> CC: David Woodhouse <David.Woodhouse@intel.com>
> CC: Matthew Garrett <matthew.garrett@nebula.com>
> CC: ibm-acpi-devel@lists.sourceforge.net
> CC: platform-driver-x86@vger.kernel.org
> CC: linux-kernel@vger.kernel.org
Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
--
"One disk to rule them all, One disk to find them. One disk to bring
them all and in the darkness grind them. In the Land of Redmond
where the shadows lie." -- The Silicon Valley Tarot
Henrique Holschuh
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-02-13 13:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-12 20:58 [PATCH] x86, acpi: LLVMLinux: Remove nested functions from Thinkpad ACPI dl9pf
2014-02-12 21:11 ` Christoph Hellwig
2014-02-12 21:20 ` Behan Webster
2014-02-12 21:27 ` Måns Rullgård
2014-02-12 21:32 ` Richard Weinberger
2014-02-12 21:54 ` David Rientjes
2014-02-12 22:01 ` Al Viro
2014-02-13 13:03 ` Henrique de Moraes Holschuh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox