From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Maxime Ripard <mripard@kernel.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
Emma Anholt <emma@anholt.net>, Jonathan Corbet <corbet@lwn.net>,
linux-kernel@vger.kernel.org,
Samuel Holland <samuel@sholland.org>,
Sandy Huang <hjc@rock-chips.com>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
linux-doc@vger.kernel.org, Hans Verkuil <hverkuil@xs4all.nl>,
linux-rockchip@lists.infradead.org, Chen-Yu Tsai <wens@csie.org>,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linux-sunxi@lists.linux.dev,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v4 05/45] drm/connector: Check drm_connector_init pointers arguments
Date: Fri, 1 Dec 2023 17:15:25 +0200 [thread overview]
Message-ID: <ZWn4jUsVgjubVPvB@intel.com> (raw)
In-Reply-To: <2lbs5dkpusow72koxknoautcfb6e2ygq5wledim4i572ya5xlc@stc4koneykhm>
On Fri, Dec 01, 2023 at 10:01:49AM +0100, Maxime Ripard wrote:
> On Wed, Nov 29, 2023 at 11:18:24AM +0200, Ville Syrjälä wrote:
> > On Wed, Nov 29, 2023 at 10:11:26AM +0100, Maxime Ripard wrote:
> > > Hi Ville,
> > >
> > > On Tue, Nov 28, 2023 at 03:49:08PM +0200, Ville Syrjälä wrote:
> > > > On Tue, Nov 28, 2023 at 02:29:40PM +0100, Maxime Ripard wrote:
> > > > > On Tue, Nov 28, 2023 at 02:54:02PM +0200, Jani Nikula wrote:
> > > > > > On Tue, 28 Nov 2023, Maxime Ripard <mripard@kernel.org> wrote:
> > > > > > > All the drm_connector_init variants take at least a pointer to the
> > > > > > > device, connector and hooks implementation.
> > > > > > >
> > > > > > > However, none of them check their value before dereferencing those
> > > > > > > pointers which can lead to a NULL-pointer dereference if the author
> > > > > > > isn't careful.
> > > > > >
> > > > > > Arguably oopsing on the spot is preferrable when this can't be caused by
> > > > > > user input. It's always a mistake that should be caught early during
> > > > > > development.
> > > > > >
> > > > > > Not everyone checks the return value of drm_connector_init and friends,
> > > > > > so those cases will lead to more mysterious bugs later. And probably
> > > > > > oopses as well.
> > > > >
> > > > > So maybe we can do both then, with something like
> > > > >
> > > > > if (WARN_ON(!dev))
> > > > > return -EINVAL
> > > > >
> > > > > if (drm_WARN_ON(dev, !connector || !funcs))
> > > > > return -EINVAL;
> > > > >
> > > > > I'd still like to check for this, so we can have proper testing, and we
> > > > > already check for those pointers in some places (like funcs in
> > > > > drm_connector_init), so if we don't cover everything we're inconsistent.
> > > >
> > > > People will invariably cargo-cult this kind of stuff absolutely
> > > > everywhere and then all your functions will have tons of dead
> > > > code to check their arguments.
> > >
> > > And that's a bad thing because... ?
> > >
> > > Also, are you really saying that checking that your arguments make sense
> > > is cargo-cult?
> > >
> > > We're already doing it in some parts of KMS, so we have to be
> > > consistent, and the answer to "most drivers don't check the error"
> > > cannot be "let's just give on error checking then".
> > >
> > > > I'd prefer not to go there usually.
> > > >
> > > > 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.
> > >
> > > Honestly, I don't care as long as it's something we can unit-test to
> > > make sure we make it consistent. We can't unit test a complete kernel
> > > crash.
> >
> > Why do you want to put utterly broken code into a unit test?
>
> Utterly broken code happens. It probably shouldn't, but here we are.
>
> Anyway, you mostly missed the consistent part.
>
> The current state with it is:
>
> - planes:
> - drm_universal_plane_init warns if funcs->destroy NULL
> - drm_universal_plane_alloc errors out if funcs is NULL
> - drmm_universal_plane_alloc warns and errors out if funcs or funcs->destroy are NULL
>
> - CRTC:
> - drm_crtc_init_with_planes warns if funcs->destroy NULL
> - drmm_crtc_init_with_planes warns if funcs or funcs->destroy are NULL
> - drmm_crtc_alloc_with_planes warns and errors out if funcs or funcs->destroy are NULL
>
> - encoder:
> - drm_encoder_init warns if funcs->destroy NULL
> - drmm_encoder_init warns and errors out if funcs or funcs->destroy are NULL
> - drmm_encoder_alloc warns and errors out if funcs or funcs->destroy are NULL
>
> - connectors:
> - drm_connector_init warns and errors out if funcs or funcs->destroy are NULL
> - drm_connector_init_with_ddc warns and errors out if funcs or funcs->destroy are NULL
> - drmm_connector_init warns and errors out if funcs or funcs->destroy are NULL
Those are perhaps fine, as things may not oops immediately if you get
that wrong. But NULL checking things that will anyway oops immediately,
(and there's not chance the thing will do anything useful if you prevent
the oops with a NULL check) doesn't make any sense to me. It just makes
you doubt the entire universe when you see code like that.
>
> I think that just proves that your opinion is just not as clear cut as
> you'd like it to be, and it's far from being the policy you claim it is.
>
> Plus, we're not even remotely consistent there, and we're not
> documenting that anywhere.
>
> And we have plenty of other examples of static stuff being checked
> because it just makes sense. All variants of drm_crtc_init_with_planes
> will for example check that the correct plane type is associated to the
> primary and cursor planes.
>
> We should fix that.
Ideally the compiler should catch all of this. But given we are
implementing this in C (and even C23 constexpr was neutered beyond
uselessness) that's not really possible in any nice way :(
--
Ville Syrjälä
Intel
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-12-01 15:16 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 10:24 [PATCH v4 00/45] drm/connector: Create HDMI Connector infrastructure Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 01/45] drm/tests: helpers: Include missing drm_drv header Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 02/45] drm/tests: helpers: Add atomic helpers Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 03/45] drm/tests: Add helper to create mock plane Maxime Ripard
2023-11-28 14:57 ` kernel test robot
2023-11-28 10:24 ` [PATCH v4 04/45] drm/tests: Add helper to create mock crtc Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 05/45] drm/connector: Check drm_connector_init pointers arguments Maxime Ripard
2023-11-28 12:54 ` Jani Nikula
2023-11-28 13:29 ` Maxime Ripard
2023-11-28 13:49 ` Ville Syrjälä
2023-11-29 9:11 ` Maxime Ripard
2023-11-29 9:18 ` Ville Syrjälä
2023-12-01 9:01 ` Maxime Ripard
2023-12-01 15:15 ` Ville Syrjälä [this message]
2023-11-29 9:38 ` Jani Nikula
2023-11-29 11:10 ` Maxime Ripard
2023-11-29 11:40 ` Jani Nikula
2023-11-29 13:26 ` Maxime Ripard
2023-11-29 10:12 ` Pekka Paalanen
2023-11-29 10:25 ` Ville Syrjälä
2023-12-01 15:17 ` Ville Syrjälä
2023-11-28 10:24 ` [PATCH v4 06/45] drm/tests: connector: Add tests for drmm_connector_init Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 07/45] drm/connector: Introduce an HDMI connector initialization function Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 08/45] drm/connector: hdmi: Create an HDMI sub-state Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 09/45] drm/connector: hdmi: Add Broadcast RGB property Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 10/45] drm/connector: hdmi: Add RGB Quantization Range to the connector state Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 11/45] drm/connector: hdmi: Add output BPC " Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 12/45] drm/connector: hdmi: Add support for output format Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 13/45] drm/connector: hdmi: Add HDMI compute clock helper Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 14/45] drm/connector: hdmi: Calculate TMDS character rate Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 15/45] drm/connector: hdmi: Add custom hook to filter " Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 16/45] drm/connector: hdmi: Compute bpc and format automatically Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 17/45] drm/connector: hdmi: Add Infoframes generation Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 18/45] drm/connector: hdmi: Create Infoframe DebugFS entries Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 19/45] drm/vc4: hdmi: Create destroy state implementation Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 20/45] drm/vc4: hdmi: Switch to HDMI connector Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 21/45] drm/vc4: tests: Remove vc4_dummy_plane structure Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 22/45] drm/vc4: tests: Convert to plane creation helper Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 23/45] drm/rockchip: inno_hdmi: Remove useless mode_fixup Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 24/45] drm/rockchip: inno_hdmi: Remove useless copy of drm_display_mode Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 25/45] drm/rockchip: inno_hdmi: Switch encoder hooks to atomic Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 26/45] drm/rockchip: inno_hdmi: Get rid of mode_set Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 27/45] drm/rockchip: inno_hdmi: no need to store vic Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 28/45] drm/rockchip: inno_hdmi: Remove unneeded has audio flag Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 29/45] drm/rockchip: inno_hdmi: Remove useless input format Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 30/45] drm/rockchip: inno_hdmi: Remove useless output format Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 31/45] drm/rockchip: inno_hdmi: Remove useless colorimetry Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 32/45] drm/rockchip: inno_hdmi: Remove useless enum Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 33/45] drm/rockchip: inno_hdmi: Remove tmds rate from structure Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 34/45] drm/rockchip: inno_hdmi: Remove useless coeff_csc matrix Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 35/45] drm/rockchip: inno_hdmi: Remove useless mode_valid Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 36/45] drm/rockchip: inno_hdmi: Move infoframe disable to separate function Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 37/45] drm/rockchip: inno_hdmi: Create mask retrieval functions Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 38/45] drm/rockchip: inno_hdmi: Switch to infoframe type Maxime Ripard
2023-11-28 11:45 ` Johan Jonker
2023-11-28 10:24 ` [PATCH v4 39/45] drm/rockchip: inno_hdmi: Remove unused drm device pointer Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 40/45] drm/rockchip: inno_hdmi: Switch to HDMI connector Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 41/45] drm/sun4i: hdmi: Convert encoder to atomic Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 42/45] drm/sun4i: hdmi: Move mode_set into enable Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 43/45] drm/sun4i: hdmi: Switch to container_of_const Maxime Ripard
2023-11-28 14:11 ` [v4,43/45] " Sui Jingfeng
2023-11-28 10:24 ` [PATCH v4 44/45] drm/sun4i: hdmi: Consolidate atomic_check and mode_valid Maxime Ripard
2023-11-28 10:24 ` [PATCH v4 45/45] drm/sun4i: hdmi: Switch to HDMI connector Maxime Ripard
2023-11-28 10:45 ` [PATCH v4 00/45] drm/connector: Create HDMI Connector infrastructure Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZWn4jUsVgjubVPvB@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=emma@anholt.net \
--cc=hjc@rock-chips.com \
--cc=hverkuil@xs4all.nl \
--cc=jani.nikula@linux.intel.com \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=mripard@kernel.org \
--cc=samuel@sholland.org \
--cc=tzimmermann@suse.de \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).