* [PATCH RFC] input/elants_i2c: Detect enum overflow
@ 2021-02-10 16:25 Josh Poimboeuf
2021-02-11 2:19 ` Michał Mirosław
0 siblings, 1 reply; 2+ messages in thread
From: Josh Poimboeuf @ 2021-02-10 16:25 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Michał Mirosław, linux-kernel, Peter Zijlstra,
linux-input, Randy Dunlap
If an enum value were to get added without updating this switch
statement, the unreachable() annotation would trigger undefined
behavior, causing execution to fall through the end of the function,
into the next one.
Make the error handling more robust for an unexpected enum value, by
doing BUG() instead of unreachable().
Fixes the following objtool warning:
drivers/input/touchscreen/elants_i2c.o: warning: objtool: elants_i2c_initialize() falls through to next function elants_i2c_resume()
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
drivers/input/touchscreen/elants_i2c.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index 6f57ec579f00..4c2b579f6c8b 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -656,8 +656,7 @@ static int elants_i2c_initialize(struct elants_data *ts)
error = elants_i2c_query_ts_info_ektf(ts);
break;
default:
- unreachable();
- break;
+ BUG();
}
if (error)
--
2.29.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RFC] input/elants_i2c: Detect enum overflow
2021-02-10 16:25 [PATCH RFC] input/elants_i2c: Detect enum overflow Josh Poimboeuf
@ 2021-02-11 2:19 ` Michał Mirosław
0 siblings, 0 replies; 2+ messages in thread
From: Michał Mirosław @ 2021-02-11 2:19 UTC (permalink / raw)
To: Josh Poimboeuf
Cc: Dmitry Torokhov, linux-kernel, Peter Zijlstra, linux-input, Randy Dunlap
On Wed, Feb 10, 2021 at 10:25:28AM -0600, Josh Poimboeuf wrote:
> If an enum value were to get added without updating this switch
> statement, the unreachable() annotation would trigger undefined
> behavior, causing execution to fall through the end of the function,
> into the next one.
>
> Make the error handling more robust for an unexpected enum value, by
> doing BUG() instead of unreachable().
>
> Fixes the following objtool warning:
>
> drivers/input/touchscreen/elants_i2c.o: warning: objtool: elants_i2c_initialize() falls through to next function elants_i2c_resume()
>
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Acked-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Reviewed-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
> drivers/input/touchscreen/elants_i2c.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
> index 6f57ec579f00..4c2b579f6c8b 100644
> --- a/drivers/input/touchscreen/elants_i2c.c
> +++ b/drivers/input/touchscreen/elants_i2c.c
> @@ -656,8 +656,7 @@ static int elants_i2c_initialize(struct elants_data *ts)
> error = elants_i2c_query_ts_info_ektf(ts);
> break;
> default:
> - unreachable();
> - break;
> + BUG();
> }
>
> if (error)
> --
> 2.29.2
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-02-11 2:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 16:25 [PATCH RFC] input/elants_i2c: Detect enum overflow Josh Poimboeuf
2021-02-11 2:19 ` Michał Mirosław
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).