All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Klimov <klimov.linux@gmail.com>
To: David Ellingsworth <david@identd.dyndns.org>
Cc: video4linux-list@redhat.com, Mauro Carvalho Chehab <mchehab@redhat.com>
Subject: Re: [PATCH 1/1] radio-mr800: fix unplug
Date: Sun, 23 Nov 2008 06:19:29 +0300	[thread overview]
Message-ID: <1227410369.16932.31.camel@tux.localhost> (raw)
In-Reply-To: <30353c3d0811200753h113ede02xc8708cd2dee654b3@mail.gmail.com>

Hello, David

On Thu, 2008-11-20 at 10:53 -0500, David Ellingsworth wrote:
> NACK

> video_unregister_device should _always_ be called once the device is
> disconnect, no matter how many handles are still open.
> 
> > -               radio->videodev = NULL;
> > -               if (radio->users) {
> > -                       kfree(radio->buffer);
> > -                       kfree(radio);
> > -               } else {
> > -                       radio->removed = 1;
> > -               }
> > +               kfree(radio->buffer);
> > +               kfree(radio);
> 
> You should not be freeing memory here. The video_device release
> callback should be used for this purpose. It is called once all open
> file handles are closed and after video_unregister_device has been
> called.

Well, things what you said make me feel ill at ease (feel
uncomfortable). Looks like 3 usb radio drivers don't implement right
disconnect and video release functions ?
Generaly, i took order of release/kfree-functions from dsbr100 and
si470x.

> Again, video_unregister_device should always be called from the usb
> disconnect callback.
> 
> >                kfree(radio->buffer);
> >                kfree(radio);
> 
> Again, memory should not be freed here. It should be freed by the
> video_device release callback for reasons stated above.

Ok. I were in deep quest of finding video_device release callback. I had
release function only in file_operations, but it wasn't right function.
Then i found video_device_release in video_device
amradio_videodev_template. 
Looks like disconnect function called before video_device_release in all
cases. And i need to call kfree(radio) after disconnect but before probe
function(if device pluged in again).

Do this general examples below look right ?

static struct video_device amradio_videodev_template = {
        .name           = "AverMedia MR 800 USB FM Radio",
        .fops           = &usb_amradio_fops,
        .ioctl_ops      = &usb_amradio_ioctl_ops,
        .release        = video_device_release_am,
};

I need my own release function, right ? To free radio structure.

void video_device_release_am(struct video_device *videodev)
{
        struct amradio_device *radio = video_get_drvdata(videodev);
        printk("we are in video_device_release\n");
        video_device_release(videodev);
        kfree(radio->buffer);
        kfree(radio);
}
May be something like "container_of" to get *radio from *videodev ? Or it's okay ?

static void usb_amradio_disconnect(struct usb_interface *intf)
{
        struct amradio_device *radio = usb_get_intfdata(intf);

        printk("disconnect called\n");
//      mutex_lock(&radio->disconnect_lock);
        radio->removed = 1;

        usb_set_intfdata(intf, NULL);
        video_unregister_device(radio->videodev);

//      mutex_unlock(&radio->disconnect_lock);
}

> I suspect you'll find little need for this mutex once you have
> properly implemented the video_device release callback. You may
> however still need the removed flag as some usb calls obviously can't
> be made once the device has been removed. For reference, please review
> the stk-webcam driver as it implements this properly

Thanks for pointing this out. I think that disconnect lock is not
necessarily.


-- 
Best regards, Klimov Alexey

--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

  reply	other threads:[~2008-11-23  3:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-19  0:36 [PATCH 1/1] radio-mr800: fix unplug Alexey Klimov
2008-11-20 15:53 ` David Ellingsworth
2008-11-23  3:19   ` Alexey Klimov [this message]
2008-11-24 14:35     ` David Ellingsworth
2008-11-27 12:00       ` Alexey Klimov
2008-11-30  5:19         ` David Ellingsworth
2008-12-06  0:04           ` Alexey Klimov
2008-12-06 10:05             ` Mauro Carvalho Chehab
2008-12-09  1:35               ` [please review patch] dsbr100: fix unplug oops Alexey Klimov
2008-12-09 14:02                 ` David Ellingsworth
2008-12-09 20:55                   ` [PATCH] " Alexey Klimov
2008-12-12  3:05                     ` Douglas Schilling Landgraf

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=1227410369.16932.31.camel@tux.localhost \
    --to=klimov.linux@gmail.com \
    --cc=david@identd.dyndns.org \
    --cc=mchehab@redhat.com \
    --cc=video4linux-list@redhat.com \
    /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.