Re: [PATCH] Convert dmasound_awacs to dynamic input_dev allocation

From: Ian Wienand
Date: Mon Oct 31 2005 - 22:59:31 EST


On Mon, Oct 31, 2005 at 10:17:08PM -0500, Dmitry Torokhov wrote:
> > + awacs_beep_dev = input_allocate_device();
>
> We really need to check whether device was allocated here...

AFAICS there is no easy way to bail without leaking from that point
(the comment already there suggests as much). Would it be appropriate
to just BUG() out in that case and save somebody auditing and
re-architecturing for an unlikely error in a deprecated interface?

-i

Signed-off-by: Ian Wienand <ianw@xxxxxxxxxxxxxxxxxx>

---
diff --git a/sound/oss/dmasound/dmasound_awacs.c b/sound/oss/dmasound/dmasound_awacs.c
--- a/sound/oss/dmasound/dmasound_awacs.c
+++ b/sound/oss/dmasound/dmasound_awacs.c
@@ -2805,16 +2805,7 @@ __init setup_beep(void)
return 0 ;
}

-static struct input_dev awacs_beep_dev = {
- .evbit = { BIT(EV_SND) },
- .sndbit = { BIT(SND_BELL) | BIT(SND_TONE) },
- .event = awacs_beep_event,
- .name = "dmasound beeper",
- .phys = "macio/input0", /* what the heck is this?? */
- .id = {
- .bustype = BUS_HOST,
- },
-};
+static struct input_dev *awacs_beep_dev;

int __init dmasound_awacs_init(void)
{
@@ -3136,18 +3127,32 @@ printk("dmasound_pmac: Awacs/Screamer Co
break ;
}

+ awacs_beep_dev = input_allocate_device();
/*
* XXX: we should handle errors here, but that would mean
* rewriting the whole init code. later..
*/
- input_register_device(&awacs_beep_dev);
+ if (awacs_beep_dev == NULL)
+ {
+ printk(KERN_ERR "%s() input_allocate_device failed\n", __FUNCTION__);
+ BUG();
+ }
+
+ awacs_beep_dev->name = "dmasound beeper";
+ awacs_beep_dev->phys = "macio/input0";
+ awacs_beep_dev->id.bustype = BUS_HOST;
+ awacs_beep_dev->event = awacs_beep_event;
+ awacs_beep_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
+ awacs_beep_dev->evbit[0] = BIT(EV_SND);
+
+ input_register_device(awacs_beep_dev);

return dmasound_init();
}

static void __exit dmasound_awacs_cleanup(void)
{
- input_unregister_device(&awacs_beep_dev);
+ input_unregister_device(awacs_beep_dev);

switch (awacs_revision) {
case AWACS_TUMBLER:
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/