From: Takashi Iwai <tiwai@suse.de>
To: Jaroslav Kysela <perex@perex.cz>
Cc: ALSA development <alsa-devel@alsa-project.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
dtor@mail.ru, Sebastian Siewior <al+sa@ml.breakpoint.cc>,
Mark Brown <broonie@opensource.wolfsonmicro.com>,
linux-input@vger.kernel.org
Subject: Re: [RFC] ucb1400 touchscreen, irq auto probing and ac97 with its private field
Date: Fri, 25 Apr 2008 11:17:53 +0200 [thread overview]
Message-ID: <s5hprsel2da.wl%tiwai@suse.de> (raw)
In-Reply-To: <Pine.LNX.4.61.0804251008270.7882@tm8103.perex-int.cz>
At Fri, 25 Apr 2008 10:23:51 +0200 (CEST),
Jaroslav Kysela wrote:
>
> On Fri, 25 Apr 2008, Takashi Iwai wrote:
>
> > At Fri, 25 Apr 2008 09:35:47 +0200 (CEST),
> > Jaroslav Kysela wrote:
> > >
> > > On Fri, 25 Apr 2008, Takashi Iwai wrote:
> > >
> > > > > Sure. I applied the simple 'void *device_private_data' patch, because
> > > > > current usage request is really trivial. We can implement complex code to
> > > > > handle data for multiple "extra" devices on AC97 bus later.
> > > >
> > > > Actually, it's not "used" yet. The ucb1000 reads the data but no one
> > > > stores yet. And, if its usage request is trivial, we should use "int
> > >
> > > Yes, I hope that the appropriate initialization code will be added to SoC
> > > drivers, too.
> > >
> > > > irq" as in the original patch instead of void data and cast.
> > >
> > > But other SoC (or other) drivers might want to pass to extra devices on
> > > AC97 bus something different or more complex. Mark Brown already noted
> > > that. I would keep it as 'void *'.
> >
> > That's the very problem I've been trying to point out.
> > The void pointer is good if the same driver assigns and casts. But,
> > in this case, the allocator and the receiver are different. Thus,
> > there is no guarantee that the data type is what you want. OTOH, if
> > it's "int irq", this is crystal clear.
> >
> > So, in short:
> >
> > - if only one device needs such data, it should be a strong type like
> > "int irq" anyway -- no extra need to cast to void pointer
> > - if multiple devices need such a pass-away mechanism, then they can
> > crash because you have no data type check. The void pointer is
> > dangerous for multiple devices.
>
> I see. In this case, I would propose to add a 32-bit "magic" at the
> start of 'void *' data. How about this modification:
The magic number sounds OK, but funky cast to integer pointer is bad.
If you have a long or a pointer after int, you can have an alignment
problem on 64bit archs, for example.
Defining a simple struct would be safer and easier.
thanks,
Takashi
>
> diff -r e2ff47e8771b include/ac97_codec.h
> --- a/include/ac97_codec.h Fri Apr 25 08:29:05 2008 +0200
> +++ b/include/ac97_codec.h Fri Apr 25 10:22:00 2008 +0200
> @@ -407,6 +407,9 @@
> #define AC97_RATES_MIC_ADC 4
> #define AC97_RATES_SPDIF 5
>
> +/* device private data magic number */
> +#define AC97_PDEVMAGIC_IRQ 0x20495251 /* in ASCII: <space>IRQ */
> +
> /*
> *
> */
> @@ -545,6 +547,11 @@ static inline int ac97_can_spdif(struct
> static inline int ac97_can_spdif(struct snd_ac97 * ac97)
> {
> return (ac97->ext_id & AC97_EI_SPDIF) != 0;
> +}
> +static inline int ac97_check_pdevdata_magic(struct snd_ac97 * ac97, unsigned int magic)
> +{
> + return (ac97->device_private_data &&
> + *((unsigned int *)ac97->device_private_data) == magic);
> }
>
> /* functions */
> diff -r e2ff47e8771b kernel/drivers/input/touchscreen/ucb1400_ts.c
> --- a/kernel/drivers/input/touchscreen/ucb1400_ts.c Fri Apr 25 08:29:05 2008 +0200
> +++ b/kernel/drivers/input/touchscreen/ucb1400_ts.c Fri Apr 25 10:22:00 2008 +0200
> @@ -492,14 +492,14 @@ static int ucb1400_ts_probe(struct devic
> goto err_free_devs;
> }
>
> - if (!ucb->ac97->device_private_data) {
> + if (!ac97_check_pdevdata_magic(usb->ac97, AC97_PDEVMAGIC_IRQ)) {
> error = ucb1400_detect_irq(ucb);
> if (error) {
> printk(KERN_ERR "UCB1400: IRQ probe failed\n");
> goto err_free_devs;
> }
> } else {
> - ucb->irq = (int) ucb->ac97->device_private_data;
> + ucb->irq = ((int *) ucb->ac97->device_private_data)[1];
> }
>
> error = request_irq(ucb->irq, ucb1400_hard_irq, IRQF_TRIGGER_RISING,
>
> Jaroslav
>
> -----
> Jaroslav Kysela <perex@perex.cz>
> Linux Kernel Sound Maintainer
> ALSA Project, Red Hat, Inc.
>
next prev parent reply other threads:[~2008-04-25 9:17 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-24 14:04 [RFC] ucb1400 touchscreen, irq auto probing and ac97 with its private field Sebastian Siewior
2008-04-24 14:32 ` Jaroslav Kysela
2008-04-24 14:35 ` Sebastian Siewior
2008-04-24 14:57 ` Mark Brown
2008-04-24 15:02 ` [alsa-devel] " Mark Brown
2008-04-24 15:44 ` Sebastian Siewior
2008-04-24 21:33 ` [alsa-devel] " Mark Brown
2008-04-24 15:02 ` Mark Brown
2008-04-24 15:35 ` [alsa-devel] " Sebastian Siewior
2008-04-24 20:04 ` Mark Brown
2008-04-24 16:09 ` [alsa-devel] " Takashi Iwai
2008-04-24 18:56 ` Mark Brown
2008-04-25 7:02 ` Takashi Iwai
2008-04-25 7:10 ` [alsa-devel] " Jaroslav Kysela
2008-04-25 7:18 ` Takashi Iwai
2008-04-25 7:35 ` Jaroslav Kysela
2008-04-25 7:46 ` Sebastian Siewior
2008-04-25 7:52 ` Takashi Iwai
2008-04-25 8:23 ` Jaroslav Kysela
2008-04-25 9:17 ` Takashi Iwai [this message]
2008-04-25 9:45 ` Jaroslav Kysela
2008-04-25 10:05 ` Takashi Iwai
2008-04-25 10:18 ` Jaroslav Kysela
2008-04-25 10:54 ` Sebastian Siewior
2008-04-25 11:10 ` Takashi Iwai
2008-04-25 11:22 ` [alsa-devel] " Jaroslav Kysela
2008-04-25 13:04 ` Takashi Iwai
2008-04-25 12:49 ` Sebastian Siewior
2008-04-25 13:01 ` Takashi Iwai
2008-04-25 15:31 ` Dmitry Torokhov
2008-04-25 9:51 ` Mark Brown
2008-04-25 10:15 ` Takashi Iwai
2008-04-25 10:20 ` Jaroslav Kysela
2008-04-25 10:28 ` [alsa-devel] " Mark Brown
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=s5hprsel2da.wl%tiwai@suse.de \
--to=tiwai@suse.de \
--cc=al+sa@ml.breakpoint.cc \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dtor@mail.ru \
--cc=linux-input@vger.kernel.org \
--cc=perex@perex.cz \
/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.