[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f810a6db9f617208302953c7cf837a8f8dd0e39f.camel@perches.com>
Date: Thu, 29 Oct 2020 14:35:50 -0700
From: Joe Perches <joe@...ches.com>
To: Nick Desaulniers <ndesaulniers@...gle.com>,
Arnd Bergmann <arnd@...nel.org>
Cc: Joshua Morris <josh.h.morris@...ibm.com>,
Philip Kelleher <pjk1939@...ux.ibm.com>,
Arnd Bergmann <arnd@...db.de>, Jens Axboe <axboe@...nel.dk>,
Nathan Chancellor <natechancellor@...il.com>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
Bjorn Helgaas <bhelgaas@...gle.com>,
linux-block@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>,
clang-built-linux <clang-built-linux@...glegroups.com>
Subject: Re: [PATCH net-next 03/11] rsxx: remove extraneous 'const' qualifier
On Thu, 2020-10-29 at 12:34 -0700, Nick Desaulniers wrote:
> On Mon, Oct 26, 2020 at 2:31 PM Arnd Bergmann <arnd@...nel.org> wrote:
> >
> > From: Arnd Bergmann <arnd@...db.de>
> >
> > The returned string from rsxx_card_state_to_str is 'const',
> > but the other qualifier doesn't change anything here except
> > causing a warning with 'clang -Wextra':
> >
> > drivers/block/rsxx/core.c:393:21: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
> > static const char * const rsxx_card_state_to_str(unsigned int state)
> >
> > Fixes: f37912039eb0 ("block: IBM RamSan 70/80 trivial changes.")
> > Signed-off-by: Arnd Bergmann <arnd@...db.de>
>
> Reviewed-by: Nick Desaulniers <ndesaulniers@...gle.com>
Perhaps this should also be converted to avoid any possible
dereference of strings with an invalid state.
---
drivers/block/rsxx/core.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c
index 8799e3bab067..f50b00b4887f 100644
--- a/drivers/block/rsxx/core.c
+++ b/drivers/block/rsxx/core.c
@@ -390,15 +390,27 @@ static irqreturn_t rsxx_isr(int irq, void *pdata)
}
/*----------------- Card Event Handler -------------------*/
-static const char * const rsxx_card_state_to_str(unsigned int state)
+static const char *rsxx_card_state_to_str(unsigned int state)
{
static const char * const state_strings[] = {
- "Unknown", "Shutdown", "Starting", "Formatting",
- "Uninitialized", "Good", "Shutting Down",
- "Fault", "Read Only Fault", "dStroying"
+ "Unknown", /* no bit set - all zeros */
+ "Shutdown", /* BIT(0) */
+ "Starting", /* BIT(1) */
+ "Formatting", /* BIT(2) */
+ "Uninitialized", /* BIT(3) */
+ "Good", /* BIT(4) */
+ "Shutting Down", /* BIT(5) */
+ "Fault", /* BIT(6) */
+ "Read Only Fault", /* BIT(7) */
+ "Destroying" /* BIT(8) */
};
- return state_strings[ffs(state)];
+ int i = ffs(state);
+
+ if (i >= ARRAY_SIZE(state_strings))
+ return "Invalid state";
+
+ return state_strings[i];
}
static void card_state_change(struct rsxx_cardinfo *card,
Powered by blists - more mailing lists