All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Francois Moine <moinejf@free.fr>
To: unlisted-recipients:; (no To-header on input)@canuck.infradead.org
Cc: linux-media@vger.kernel.org
Subject: Re: Cleanup proposal for media/gspca
Date: Thu, 17 Nov 2011 11:07:16 +0100	[thread overview]
Message-ID: <20111117110716.6343d46c@tele> (raw)
In-Reply-To: <CALF0-+V+rEYi1of3jUGeVZsF2Ms215k0_CQjJx0qnPDUuC1BQQ@mail.gmail.com>

On Wed, 16 Nov 2011 15:19:04 -0300
Ezequiel García <elezegarcia@gmail.com> wrote:

> In 'media/video/gspca/gspca.c' I really hated this cast (maybe because
> I am too dumb to understand it):
> 
>   gspca_dev = (struct gspca_dev *) video_devdata(file);
> 
> wich is only legal because a struct video_device is the first member
> of gspca_dev. IMHO, this is 'unnecesary obfuscation'.
> The thing is the driver is surely working fine and there is no good
> reasong for the change.
> 
> Is it ok to submit a patchset to change this? Something like this:
> 
> diff --git a/drivers/media/video/gspca/gspca.c
> b/drivers/media/video/gspca/gspca.c
> index 881e04c..5d962ce 100644
> --- a/drivers/media/video/gspca/gspca.c
> +++ b/drivers/media/video/gspca/gspca.c
> @@ -1304,9 +1306,11 @@ static void gspca_release(struct video_device *vfd)
>  static int dev_open(struct file *file)
>  {
>  	struct gspca_dev *gspca_dev;
> +	struct video_device *vdev;
> 
>  	PDEBUG(D_STREAM, "[%s] open", current->comm);
> -	gspca_dev = (struct gspca_dev *) video_devdata(file);
> +	vdev = video_devdata(file);
> +	gspca_dev = video_get_drvdata(vdev);
>  	if (!gspca_dev->present)

Hi Ezequiel,

You are right, the cast is not a good way (and there are a lot of them
in the gspca subdrivers), but your patch does not work because the
'private_data' of the device is not initialized (there is no call to
video_set_drvdata).

So, a possible cleanup could be:

> -	gspca_dev = (struct gspca_dev *) video_devdata(file);
> +	gspca_dev = container_of(video_devdata(file), struct gspca_dev, vdev);

Is it OK for you?

-- 
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/

  reply	other threads:[~2011-11-17 10:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20111116013445.GA5273@localhost>
2011-11-16 18:19 ` Cleanup proposal for media/gspca Ezequiel García
2011-11-17 10:07   ` Jean-Francois Moine [this message]
2011-11-17 18:03     ` Ezequiel
2011-11-19 18:59     ` Ezequiel
2011-11-20  7:24       ` Jean-Francois Moine
2011-11-21 23:24         ` Ezequiel

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=20111117110716.6343d46c@tele \
    --to=moinejf@free.fr \
    --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.