All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dtor@insightbb.com>
To: Adrian McMenamin <lkmladrian@gmail.com>
Cc: Arjan van de Ven <arjan@infradead.org>,
	Paul Mundt <lethal@linux-sh.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] Maple bus support for the Sega Dreamcast - keyboard support
Date: Sun, 9 Sep 2007 23:50:46 -0400	[thread overview]
Message-ID: <200709092350.47602.dtor@insightbb.com> (raw)
In-Reply-To: <8b67d60709091357k2bc0c673kef5716a97f07bd3a@mail.gmail.com>

Hi Adrian,

On Sunday 09 September 2007 16:57, Adrian McMenamin wrote:
> 
> Add maple bus keyboard support to the kernel.
> 
> Signed-off by Adrian McMenamin <adrian@mcmen.demon.co.uk>
> 

Couple of more things:

> +
> +extern int maple_driver_register(struct device_driver *drv);
> +

No externs in *.c files, please. Isn't this defined in maple.h which is
being included?

> +
> +static void dc_kbd_callback(struct mapleq *mq)
> +{
> +	struct maple_device *mapledev = mq->dev;
> +	struct dc_kbd *kbd = mapledev->private_data;
> +	unsigned long *buf = mq->recvbuf;

I very much prefer an empty line between variables and the code.

> +	if (!mutex_trylock(&maple_keyb_mutex)) /* Can only be locked if
> already in cleanup */
> +		return;
> +	if (buf[1] == mapledev->function) {
> +		memcpy(kbd->new, buf + 2, 8);
> +		dc_scan_kbd(kbd);
> +	}
> +	mutex_unlock(&maple_keyb_mutex);
> +}
> +
> +static int dc_kbd_connect(struct maple_device *dev)
> +{
> +	int i, retval = 0;
> +	struct dc_kbd *kbd;
> +	if (!(dev->function & MAPLE_FUNC_KEYBOARD))
> +		return -EINVAL;
> +
> +	kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
> +	if (unlikely(!kbd))
> +		return -ENOMEM;
> +
> +	dev->private_data = kbd;
> +	kbd->dev = input_allocate_device();
> +	if (!kbd->dev){
> +		retval = -ENODEV;
> +		goto cleanup_memory;
> +	}
> +
> +	for (i = 0; i < NR_SCANCODES; i++)
> +		kbd->keycode[i] = dc_kbd_keycode[i];

memcpy?

> +	kbd->dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
> +	kbd->dev->keycodesize = sizeof (unsigned char);
> +	kbd->dev->keycodemax = ARRAY_SIZE(kbd->keycode);
> +	kbd->dev->keycode = kbd->keycode;
> +
> +
> +	for (i = 0; i < 255; i++)

Are you sure it is 255 and not NR_SCANCODES?
 
> +		set_bit(dc_kbd_keycode[i], kbd->dev->keybit);
> +
> +	clear_bit(0, kbd->dev->keybit);
> +
> +	kbd->dev->private = kbd;

Please use input_set_drvdata() here and input_get_drvdata() when
accessing it.

> +
> +	kbd->dev->name = dev->product_name;
> +	kbd->dev->id.bustype = BUS_HOST;
> +

maple_device appears to be fully integrated in sysfs, please add:
	kbd->dev->dev.parent = &dev->dev;

Btw, introducing a temp for kbd->dev should reduce generated code
somewhat.

> +	retval = input_register_device(kbd->dev);
> +	if (retval)
> +		goto cleanup;
> +	/* Maple polling is locked to VBLANK - which may be just 50/s */
> +	maple_getcond_callback(dev, dc_kbd_callback, HZ/50,
> +			       MAPLE_FUNC_KEYBOARD);
> +	return retval;
> +
> +cleanup:
> +	input_free_device(kbd->dev);
> +cleanup_memory:
> +	kfree(kbd);
> +	return retval;
> +}
> +
> +static void dc_kbd_disconnect(struct maple_device *dev)
> +{
> +	struct dc_kbd *kbd;
> +	mutex_lock(&maple_keyb_mutex);
> +	kbd = dev->private_data;
> +
> +	input_unregister_device(kbd->dev);
> +	kfree(kbd);
> +	mutex_unlock(&maple_keyb_mutex);
> +}
> +
> +/* allow the keyboard to be used */
> +static int probe_maple_kbd(struct device *dev)
> +{
> +	struct maple_device *mdev;
> +	struct maple_driver *mdrv;
> +	int proberes;
> +
> +	mdev = to_maple_dev(dev);
> +	mdrv = to_maple_driver(dev->driver);
> +
> +	proberes = dc_kbd_connect(mdev);
> +	if (unlikely(proberes))
> +		return proberes;
> +	mdev->driver = mdrv;
> +	mdev->registered = 1;
> +	return 0;
> +}
> +
> +static struct maple_driver dc_kbd_driver = {
> +	.function = MAPLE_FUNC_KEYBOARD,
> +	.connect = dc_kbd_connect,
> +	.disconnect = dc_kbd_disconnect,
> +	.drv = {
> +		.name = "Dreamcast_keyboard",
> +		.probe = probe_maple_kbd,
> +		},
> +};
> +
> +static int __init dc_kbd_init(void)
> +{
> +	int retval;
> +	retval = maple_driver_register(&dc_kbd_driver.drv);
> +	if (retval)
> +		return retval;
> +	return 0;

"return maple_driver_register(&dc_kbd_driver.drv);" is much shorter...

> +}
> +
> +static void __exit dc_kbd_exit(void)
> +{
> +	driver_unregister(&dc_kbd_driver.drv);
> +}
> +
> +module_init(dc_kbd_init);
> +module_exit(dc_kbd_exit);

If these are fixed you may add:

	 Acked-by: Dmitry Torokhov <dtor@mail.ru>

Thank you.

-- 
Dmitry

  parent reply	other threads:[~2007-09-10  3:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-09 17:01 [PATCH 2/3] Maple bus support for the Sega Dreamcast - keyboard support Adrian McMenamin
2007-09-09 18:30 ` Arjan van de Ven
2007-09-09 20:35   ` Adrian McMenamin
2007-09-09 20:44     ` Arjan van de Ven
2007-09-09 20:57       ` Adrian McMenamin
2007-09-09 21:03         ` Arjan van de Ven
2007-09-10  3:50         ` Dmitry Torokhov [this message]
2007-09-10 14:28           ` Adrian McMenamin
2007-09-10 15:11             ` Dmitry Torokhov

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=200709092350.47602.dtor@insightbb.com \
    --to=dtor@insightbb.com \
    --cc=arjan@infradead.org \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkmladrian@gmail.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.