All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: "Erling Ljunggren (hljunggr)" <hljunggr@cisco.com>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"jonathansb1@gmail.com" <jonathansb1@gmail.com>
Subject: Re: [PATCH 4/5] media: i2c: cat24c208: driver for the cat24c208 EDID EEPROM
Date: Tue, 2 Aug 2022 18:26:31 +0200	[thread overview]
Message-ID: <CAHp75VeAKbJYB0pQOR9oVXFTaQm+G_R14zrzRe9qEPDqK1ttNw@mail.gmail.com> (raw)
In-Reply-To: <403e5055-81dd-7426-a3cd-f3c3bbf24179@xs4all.nl>

On Tue, Aug 2, 2022 at 2:58 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
> On 8/2/22 14:49, Andy Shevchenko wrote:
> > On Tue, Aug 2, 2022 at 2:45 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
> >> On 8/2/22 14:26, Andy Shevchenko wrote:
> >>> On Tue, Aug 2, 2022 at 2:23 PM Andy Shevchenko
> >>> <andy.shevchenko@gmail.com> wrote:
> >>>> On Tue, Aug 2, 2022 at 2:21 PM Andy Shevchenko
> >>>> <andy.shevchenko@gmail.com> wrote:

...

> >>>>> You are blaming the wrong man here, i.e. devm. The problem as I stated
> >>>>> above is developers who do not understand (pay attention to) the
> >>>>> lifetime of the objects.
> >>>>
> >>>> That said, the devm has nothing to do with the driver still being
> >>>> problematic for the scenario you described, no?
> >>>
> >>> And the cleanest (at the first glance) solution is to make v4l2 to fix
> >>> this bug by suppressing unbind attributes when the device is opened
> >>> for all v4l2 subdev drivers, and restore it back when it's closed.
> >>
> >> Why would we do that? The patch works in the scenario that I described:
> >> the memory is freed in the struct video_device release() callback, which
> >> is called when the last reference to the video node goes away. This is
> >> standard V4L2 framework behavior that works great in the case of a unbind.
> >>
> >> Without devm_kzalloc it works fine, even when unbind is called. With
> >> devm_kzalloc the unbind attributes would have to be suppressed. I see no
> >> reason for that as media maintainer.
> >
> > I'm not sure anymore that we are talking about the same thing.
> >
> > Your driver allocates memory with kzalloc() in ->probe() and frees it
> > in ->remove(). How is this different from the lifetime of a devm:ed
> > object? If what you said is true, than driver is still problematic,
> > since ->remove() frees this memory the very same way at unbind call.
>
> No, it is not freed in remove(). remove() calls video_unregister_device(),
> and that calls cat24c208_release() when the last user of /dev/videoX closes
> its filehandle. And it is cat24c208_release() that finally frees the memory.

Okay, I got it.

So, if you unbind the driver the state will be stale and still being
accessible by the user (with outdated info). Now, what happens if you
unbind and try to bind back, while the user is slow enough to close
the device file?

Also it's still racy against any i2c calls done via IOCTLs, because
you have unregistered I2C devices.

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2022-08-02 16:27 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-28 11:40 [PATCH 0/5] Add the cat24c208 EDID EEPROM driver + new EDID capability Erling Ljunggren
2022-07-28 11:40 ` [PATCH 1/5] media: videodev2.h: add V4L2_CAP_EDID_MEMORY Erling Ljunggren
2022-07-28 11:40 ` [PATCH 2/5] media: docs: Add V4L2_CAP_EDID_MEMORY Erling Ljunggren
2022-07-31  9:54   ` kernel test robot
2022-07-28 11:40 ` [PATCH 3/5] dt-bindings: media: add cat24c208 bindings Erling Ljunggren
2022-07-28 13:47   ` Rob Herring
2022-07-28 11:40 ` [PATCH 4/5] media: i2c: cat24c208: driver for the cat24c208 EDID EEPROM Erling Ljunggren
     [not found]   ` <CAHp75VeKMJ7eSZ3SLki74o+LkL6CBfcx4RL90n2J20BE+8L+KA@mail.gmail.com>
2022-07-28 13:23     ` Hans Verkuil
2022-07-28 20:56       ` Andy Shevchenko
2022-07-29  7:21         ` Hans Verkuil
2022-07-29 12:00           ` Andy Shevchenko
2022-07-29 12:11             ` Hans Verkuil
2022-07-29 14:47               ` Andy Shevchenko
2022-07-29 15:34                 ` Hans Verkuil
2022-07-29 15:51   ` Andy Shevchenko
2022-08-01 13:07     ` Erling Ljunggren (hljunggr)
2022-08-01 14:57       ` Andy Shevchenko
2022-08-01 18:34         ` Hans Verkuil
2022-08-02  8:42           ` Andy Shevchenko
2022-08-02  9:06             ` Hans Verkuil
2022-08-02 12:21               ` Andy Shevchenko
2022-08-02 12:23                 ` Andy Shevchenko
2022-08-02 12:26                   ` Andy Shevchenko
2022-08-02 12:45                     ` Hans Verkuil
2022-08-02 12:49                       ` Andy Shevchenko
2022-08-02 12:58                         ` Hans Verkuil
2022-08-02 16:26                           ` Andy Shevchenko [this message]
2022-08-02 16:28                             ` Andy Shevchenko
2022-08-03  1:36   ` kernel test robot
2022-07-28 11:40 ` [PATCH 5/5] media: v4l2-dev: handle V4L2_CAP_EDID_MEMORY Erling Ljunggren

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=CAHp75VeAKbJYB0pQOR9oVXFTaQm+G_R14zrzRe9qEPDqK1ttNw@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=hljunggr@cisco.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jonathansb1@gmail.com \
    --cc=linux-media@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.