[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZWn5D387DYmsh1sa@intel.com>
Date: Fri, 1 Dec 2023 17:17:35 +0200
From: Ville Syrjälä <ville.syrjala@...ux.intel.com>
To: Pekka Paalanen <ppaalanen@...il.com>
Cc: Jernej Skrabec <jernej.skrabec@...il.com>,
Emma Anholt <emma@...olt.net>,
Jonathan Corbet <corbet@....net>,
dri-devel@...ts.freedesktop.org,
Samuel Holland <samuel@...lland.org>,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
Sandy Huang <hjc@...k-chips.com>,
Hans Verkuil <hverkuil@...all.nl>,
linux-rockchip@...ts.infradead.org, Chen-Yu Tsai <wens@...e.org>,
Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>,
linux-sunxi@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org,
linux-media@...r.kernel.org
Subject: Re: [PATCH v4 05/45] drm/connector: Check drm_connector_init
pointers arguments
On Wed, Nov 29, 2023 at 12:25:37PM +0200, Ville Syrjälä wrote:
> On Wed, Nov 29, 2023 at 12:12:59PM +0200, Pekka Paalanen wrote:
> > On Tue, 28 Nov 2023 15:49:08 +0200
> > Ville Syrjälä <ville.syrjala@...ux.intel.com> wrote:
> >
> > > Should we perhaps start to use the (arguably hideous)
> > > - void f(struct foo *bar)
> > > + void f(struct foo bar[static 1])
> > > syntax to tell the compiler we don't accept NULL pointers?
> > >
> > > Hmm. Apparently that has the same problem as using any
> > > other kind of array syntax in the prototype. That is,
> > > the compiler demands to know the definition of 'struct foo'
> > > even though we're passing in effectively a pointer. Sigh.
> >
> >
> > __attribute__((nonnull)) ?
>
> I guess that would work, though the syntax is horrible when
> you need to flag specific arguments.
I played around with this a bit (blindly cocci'd tons of
drm and i915 function declarations with the nonnull attribute)
and it's somewhat underwhelming unfortunately.
It will trip only if the compiler is 100% sure you're passing
in a NULL. There is no way to eg. tell the compiler that a
function can return a NULL and thus anything coming from it
should be checked by the caller before passing it on to
something with the nonnull attribute. And I suppose error
pointers would also screw that idea over anyway.
Additionally the NULL device checks being being done in
the drm_err/dbg macros trip this up left right and center.
And hiding that check inside a function (instead of having
it in the macro) is also ruined by the fact that we apparently
pass different types of pointers to these macros :( Generics
could be used to sort out that type mess I suppose, or the
code that passes the wrong type (DSI code at least) should
just be changed to not do that. But not sure if there's enough
benefit to warrant the work.
--
Ville Syrjälä
Intel
Powered by blists - more mailing lists