* [PATCH] mm: fix uninitialized variable warnings
@ 2018-11-02 15:31 Arnd Bergmann
2018-11-05 9:01 ` Jan Kara
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2018-11-02 15:31 UTC (permalink / raw)
To: Andrew Morton, Jan Kara
Cc: Arnd Bergmann, Michal Hocko, Wang Long, Matthew Wilcox,
Dave Chinner, linux-mm, linux-kernel
In a rare randconfig build, I got a warning about possibly uninitialized
variables:
mm/page-writeback.c: In function 'balance_dirty_pages':
mm/page-writeback.c:1623:16: error: 'writeback' may be used uninitialized in this function [-Werror=maybe-uninitialized]
mdtc->dirty += writeback;
^~
mm/page-writeback.c:1624:4: error: 'filepages' may be used uninitialized in this function [-Werror=maybe-uninitialized]
mdtc_calc_avail(mdtc, filepages, headroom);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/page-writeback.c:1624:4: error: 'headroom' may be used uninitialized in this function [-Werror=maybe-uninitialized]
The compiler evidently fails to notice that the usage is in dead code
after 'mdtc' is set to NULL when CONFIG_CGROUP_WRITEBACK is disabled.
Adding an IS_ENABLED() check makes this clear to the compiler.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
mm/page-writeback.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 3f690bae6b78..f02535b7731a 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -1611,7 +1611,7 @@ static void balance_dirty_pages(struct bdi_writeback *wb,
bg_thresh = gdtc->bg_thresh;
}
- if (mdtc) {
+ if (IS_ENABLED(CONFIG_CGROUP_WRITEBACK) && mdtc) {
unsigned long filepages, headroom, writeback;
/*
@@ -1944,7 +1944,7 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb)
wb_calc_thresh(gdtc->wb, gdtc->bg_thresh))
return true;
- if (mdtc) {
+ if (IS_ENABLED(CONFIG_CGROUP_WRITEBACK) && mdtc) {
unsigned long filepages, headroom, writeback;
mem_cgroup_wb_stats(wb, &filepages, &headroom, &mdtc->dirty,
--
2.18.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: fix uninitialized variable warnings
2018-11-02 15:31 [PATCH] mm: fix uninitialized variable warnings Arnd Bergmann
@ 2018-11-05 9:01 ` Jan Kara
2018-11-05 15:35 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2018-11-05 9:01 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andrew Morton, Jan Kara, Michal Hocko, Wang Long, Matthew Wilcox,
Dave Chinner, linux-mm, linux-kernel, Tejun Heo
On Fri 02-11-18 16:31:06, Arnd Bergmann wrote:
> In a rare randconfig build, I got a warning about possibly uninitialized
> variables:
>
> mm/page-writeback.c: In function 'balance_dirty_pages':
> mm/page-writeback.c:1623:16: error: 'writeback' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> mdtc->dirty += writeback;
> ^~
> mm/page-writeback.c:1624:4: error: 'filepages' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> mdtc_calc_avail(mdtc, filepages, headroom);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> mm/page-writeback.c:1624:4: error: 'headroom' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> The compiler evidently fails to notice that the usage is in dead code
> after 'mdtc' is set to NULL when CONFIG_CGROUP_WRITEBACK is disabled.
> Adding an IS_ENABLED() check makes this clear to the compiler.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
I'm surprised the compiler was not able to infer this since:
struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ?
&mdtc_stor : NULL;
and if CONFIG_CGROUP_WRITEBACK is disabled, mdtc_valid() is defined to
'false'. But possibly the function is just too big and the problematic
condition is in the loop so maybe it all confuses the compiler too much.
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index 3f690bae6b78..f02535b7731a 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -1611,7 +1611,7 @@ static void balance_dirty_pages(struct bdi_writeback *wb,
> bg_thresh = gdtc->bg_thresh;
> }
>
> - if (mdtc) {
> + if (IS_ENABLED(CONFIG_CGROUP_WRITEBACK) && mdtc) {
> unsigned long filepages, headroom, writeback;
Honestly, I don't like the IS_ENABLED(CONFIG_CGROUP_WRITEBACK) check here.
It just looks too arbitrary. Could we perhaps change the code like
struct dirty_throttle_control * const mdtc = &mdtc_stor;
And then replace checks for !mtdc in the function to !mdtc_valid(mdtc)?
That is the same thing as currently and it should make it obvious to the
compiler as well as human what is going on... Tejun?
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: fix uninitialized variable warnings
2018-11-05 9:01 ` Jan Kara
@ 2018-11-05 15:35 ` Arnd Bergmann
0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2018-11-05 15:35 UTC (permalink / raw)
To: Jan Kara
Cc: Andrew Morton, Michal Hocko, Wang Long, Matthew Wilcox,
Dave Chinner, linux-mm, linux-kernel, Tejun Heo
On 11/5/18, Jan Kara <jack@suse.cz> wrote:
> On Fri 02-11-18 16:31:06, Arnd Bergmann wrote:
>> In a rare randconfig build, I got a warning about possibly uninitialized
>> variables:
>>
>> mm/page-writeback.c: In function 'balance_dirty_pages':
>> mm/page-writeback.c:1623:16: error: 'writeback' may be used uninitialized
>> in this function [-Werror=maybe-uninitialized]
>> mdtc->dirty += writeback;
>> ^~
>> mm/page-writeback.c:1624:4: error: 'filepages' may be used uninitialized
>> in this function [-Werror=maybe-uninitialized]
>> mdtc_calc_avail(mdtc, filepages, headroom);
>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> mm/page-writeback.c:1624:4: error: 'headroom' may be used uninitialized in
>> this function [-Werror=maybe-uninitialized]
>>
>> The compiler evidently fails to notice that the usage is in dead code
>> after 'mdtc' is set to NULL when CONFIG_CGROUP_WRITEBACK is disabled.
>> Adding an IS_ENABLED() check makes this clear to the compiler.
>>
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> I'm surprised the compiler was not able to infer this since:
>
> struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ?
> &mdtc_stor : NULL;
>
> and if CONFIG_CGROUP_WRITEBACK is disabled, mdtc_valid() is defined to
> 'false'. But possibly the function is just too big and the problematic
> condition is in the loop so maybe it all confuses the compiler too much.
On second thought, I suspect this started with the introduction of
CONFIG_NO_AUTO_INLINE in linux-next. That also caused a similar
issue in 28 other files that I patched later. I wrote this patch before I
saw the others, and then didn't make the connection.
Let's drop the patch for now, and decide what we want to do for the
others. I fixed those by adding 'inline' markers for whatever
function needed it.
Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-05 15:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-02 15:31 [PATCH] mm: fix uninitialized variable warnings Arnd Bergmann
2018-11-05 9:01 ` Jan Kara
2018-11-05 15:35 ` Arnd Bergmann
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).