public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Mundt <lethal@linux-sh.org>
To: Ben Nizette <bn@niasdigital.com>
Cc: Hans-J?rgen Koch <hjk@linutronix.de>, gregkh <gregkh@suse.de>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] UIO: Implement a UIO interface for the SMX Cryptengine
Date: Thu, 13 Mar 2008 19:06:55 +0900	[thread overview]
Message-ID: <20080313100655.GA6705@linux-sh.org> (raw)
In-Reply-To: <1205400940.3735.15.camel@moss.renham>

On Thu, Mar 13, 2008 at 08:35:40PM +1100, Ben Nizette wrote:
> diff --git a/drivers/uio/uio_smx.c b/drivers/uio/uio_smx.c
> new file mode 100644
> index 0000000..fda8b8b
> --- /dev/null
> +++ b/drivers/uio/uio_smx.c
> @@ -0,0 +1,118 @@
> +/*
> + * UIO SMX Cryptengine driver.
> + *
> + * (C) 2008 Nias Digital P/L <bn@niasdigital.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + */
> +
> +#include <linux/device.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/uio_driver.h>
> +
> +#include <asm/io.h>
> +
linux/io.h is preferable here.

> +static int __devinit smx_ce_probe(struct platform_device *dev)
> +{
> +	struct uio_info *info;
> +	struct resource *regs;
> +
> +	info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
> +	if (!info)
> +		return -ENOMEM;
> +
> +	regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
> +	if (!regs)
> +		goto out_free;
> +
> +	info->mem[0].addr = regs->start;
> +	if (!info->mem[0].addr)
> +		goto out_free;
> +
> +	info->mem[0].size = regs->end - regs->start + 1;
> +	info->mem[0].internal_addr = ioremap(regs->start, info->mem[0].size);
> +	if (!info->mem[0].internal_addr)
> +		goto out_free;
> +
> +	info->mem[0].memtype = UIO_MEM_PHYS;
> +
> +	info->name = "smx-ce";
> +	info->version = "0.03";

You may as well use DRV_NAME and DRV_VERSION, then you can toss that over
to MODULE_VERSION() if you're so inclined. It's generally nice to keep
modinfo happy.

> +	info->irq = platform_get_irq(dev, 0);
> +	info->irq_flags = IRQF_SHARED;
> +	info->handler = smx_handler;
> +
platform_get_irq() can fail, which you don't presently handle (though I
guess uio_register_device() will error out if you hand off -ENXIO as your
IRQ anyways, so it's not technically an issue). That's a pretty minor
issue, though, but might be something you wish to fix up if you are
planning on using this as an example driver for others.

> +	platform_set_drvdata(dev, info);
> +
> +	if (uio_register_device(&dev->dev, info))
> +		goto out_unmap;
> +
> +	return 0;
> +out_unmap:
> +	iounmap(info->mem[0].internal_addr);
> +out_free:
> +	kfree(info);
> +
> +	return -ENODEV;
> +}
> +
Your error paths are also pretty quiet. A dev_err() or so in the few
failure cases you do have might not be a terrible idea.

uio_register_device() also has quite a few different error cases, so it's
at least worth preserving the error value and returning that back,
rather than always returning -ENODEV.

  reply	other threads:[~2008-03-13 10:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-13  9:35 [PATCH v3] UIO: Implement a UIO interface for the SMX Cryptengine Ben Nizette
2008-03-13 10:06 ` Paul Mundt [this message]
2008-03-13 10:24   ` Hans-Jürgen Koch
2008-03-13 10:09 ` Hans-Jürgen Koch

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=20080313100655.GA6705@linux-sh.org \
    --to=lethal@linux-sh.org \
    --cc=bn@niasdigital.com \
    --cc=gregkh@suse.de \
    --cc=hjk@linutronix.de \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox