2022-11-29 15:15:21

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] mm/writeback: fix dereferencing NULL mapping->host

On Tue, 29 Nov 2022 11:32:59 +0800
Andrew Yang <[email protected]> wrote:

> From: "andrew.yang" <[email protected]>
>
> Check before dereferencing mapping->host
>
> Signed-off-by: andrew.yang <[email protected]>
> ---
> include/trace/events/writeback.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
> index 86b2a82da546..56f6e114d3ed 100644
> --- a/include/trace/events/writeback.h
> +++ b/include/trace/events/writeback.h
> @@ -68,7 +68,7 @@ DECLARE_EVENT_CLASS(writeback_folio_template,
> strscpy_pad(__entry->name,
> bdi_dev_name(mapping ? inode_to_bdi(mapping->host) :
> NULL), 32);
> - __entry->ino = mapping ? mapping->host->i_ino : 0;
> + __entry->ino = mapping && mapping->host ? mapping->host->i_ino : 0;

I hate remembering precedence. Can we add parenthesis around this to be
clear?

__entry->ino = (mapping && mapping->host) ? mapping->host->i_ino : 0;

Thanks,

-- Steve


> __entry->index = folio->index;
> ),
>


2022-11-30 08:36:14

by Andrew Yang

[permalink] [raw]
Subject: [PATCH v2] mm/writeback: fix dereferencing NULL mapping->host

From: "andrew.yang" <[email protected]>

Check before dereferencing mapping->host

Suggested-by: Steven Rostedt <[email protected]>
Signed-off-by: andrew.yang <[email protected]>
---
v2: add parenthesis
---
include/trace/events/writeback.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index 86b2a82da546..54e353c9f919 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -68,7 +68,7 @@ DECLARE_EVENT_CLASS(writeback_folio_template,
strscpy_pad(__entry->name,
bdi_dev_name(mapping ? inode_to_bdi(mapping->host) :
NULL), 32);
- __entry->ino = mapping ? mapping->host->i_ino : 0;
+ __entry->ino = (mapping && mapping->host) ? mapping->host->i_ino : 0;
__entry->index = folio->index;
),

--
2.18.0

2022-11-30 09:31:52

by Andrew Yang

[permalink] [raw]
Subject: Re: [PATCH v2] mm/writeback: fix dereferencing NULL mapping->host

On Tue, 2022-11-29 at 09:56 -0500, Steven Rostedt wrote:
> On Tue, 29 Nov 2022 11:32:59 +0800
> Andrew Yang <[email protected]> wrote:
>
> > From: "andrew.yang" <[email protected]>
> >
> > Check before dereferencing mapping->host
> >
> > Signed-off-by: andrew.yang <[email protected]>
> > ---
> > include/trace/events/writeback.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/trace/events/writeback.h
> > b/include/trace/events/writeback.h
> > index 86b2a82da546..56f6e114d3ed 100644
> > --- a/include/trace/events/writeback.h
> > +++ b/include/trace/events/writeback.h
> > @@ -68,7 +68,7 @@ DECLARE_EVENT_CLASS(writeback_folio_template,
> > strscpy_pad(__entry->name,
> > bdi_dev_name(mapping ?
> > inode_to_bdi(mapping->host) :
> > NULL), 32);
> > - __entry->ino = mapping ? mapping->host->i_ino : 0;
> > + __entry->ino = mapping && mapping->host ? mapping-
> > >host->i_ino : 0;
>
> I hate remembering precedence. Can we add parenthesis around this to
> be
> clear?
>
> __entry->ino = (mapping && mapping->host) ? mapping-
> >host->i_ino : 0;
>
> Thanks,
>
> -- Steve
>
>
> > __entry->index = folio->index;
> > ),
> >
>
>
Sure, that's a good suggestion