From: Joe Perches <joe@perches.com>
To: Bob Smith <bsmith@linuxtoys.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 001/001] CHAR DRIVERS: a simple device to give daemons a /sys-like interface
Date: Fri, 02 Aug 2013 18:56:25 -0700 [thread overview]
Message-ID: <1375494985.2034.160.camel@joe-AO722> (raw)
In-Reply-To: <51FC5A97.1090102@linuxtoys.org>
On Fri, 2013-08-02 at 18:19 -0700, Bob Smith wrote:
> This character device can give daemons an interface similar to
> the kernel's /sys and /proc interfaces. It is a nice way to
> give user space drivers real device nodes in /dev.
Trivial notes:
> diff --git a/drivers/char/proxy.c b/drivers/char/proxy.c
[]
+int proxy_init_module(void)
> +{
> + int i, err;
> + px_devices = kmalloc(numberofdevs * sizeof(struct px), GFP_KERNEL);
> + if (px_devices == NULL) {
> + /* no memory available */
> + if (debuglevel >= 1)
> + pr_err("%s: init fails: no memory.\n",
> + DEVNAME);
OOM messages aren't necessary.
dump_stack() is already done on OOM.
> + return 0;
> + }
> + memset(px_devices, 0, numberofdevs * sizeof(struct px));
kcalloc instead of kmalloc/memset
> +
> + /* init devices in this block */
> + for (i = 0; i < numberofdevs; i++) { /* for every minor device */
> + px_devices[i].minor = i; /* set minor number */
> + px_devices[i].ewbuf.buf = (char *) 0;
> + px_devices[i].webuf.buf = (char *) 0;
> + px_devices[i].ewbuf.widx = 0;
> + px_devices[i].webuf.widx = 0;
> + px_devices[i].ewbuf.ridx = 0;
> + px_devices[i].webuf.ridx = 0;
sets to zero after zeroed alloc are redundant.
> + err = cdev_add(&px_cdev, px_devicenumber, numberofdevs);
> + if (err < 0) {
> + if (debuglevel >= 1)
> + pr_err("%s: init fails. err=%d.\n",
> + DEVNAME, err);
> + return err;
> + }
It's either an err or a debug message.
Don't hide actual errors under debugging levels.
I suggest you only use pr_debug and/or have a macro like
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#define proxy_dbg(level, fmt, ...) \
do { \
if (level >= debuglevel) \
pr_debug(fmt, ##__VA_ARGS__); \
} while (0)
> + if (debuglevel >= 2)
> + pr_info("%s: Installed %d minor devices on major number %d.\n",
> + DEVNAME, numberofdevs, px_major);
Then this (and the rest) becomes
proxy_dbg(2, "Installed %d minor devices on major %d\n",
numberofdevs, px_major);
etc...
> +static int proxy_open(struct inode *inode, struct file *filp)
> +{
> + if (!dev->ewbuf.buf) { /* get east-to-west buffer */
> + dev->ewbuf.buf = kmalloc(buffersize, GFP_KERNEL);
> + if (!dev->ewbuf.buf) {
> + if (debuglevel >= 1)
> + pr_err("%s: No memory dev=%d.\n",
> + DEVNAME, mnr);
> + up(&dev->sem);
> + return -ENOMEM;
> + }
> + }
> + if (!dev->webuf.buf) { /* get west-to-east buffer */
> + dev->webuf.buf = kmalloc(buffersize, GFP_KERNEL);
> + if (!dev->webuf.buf) {
> + if (debuglevel >= 1)
> + pr_err("%s: No memory dev=%d.\n",
> + DEVNAME, mnr);
no OOMs.
> +static int proxy_release(struct inode *inode, struct file *filp)
> +{
> + struct px *dev = (struct px *) filp->private_data;
> +
> + if (debuglevel >= 3)
> + pr_info("%s release. Minor#=%d.\n", DEVNAME,
> + ((struct px *) filp->private_data)->minor);
> +
> + if (down_interruptible(&dev->sem)) /* prevent races on close */
> + return -ERESTARTSYS;
> +
> + dev->nopen = dev->nopen - 1;
> +
> + if (dev->east == filp) {
> + dev->east = (struct file *) 0; /* mark as not in use */
s/0/NULL; (no need to cast either)
> + dev->ewbuf.cidx = dev->ewbuf.widx; /* set close index */
> + } else if (dev->west == filp) {
> + dev->west = (struct file *) 0; /* mark as not in use */
etc.
next prev parent reply other threads:[~2013-08-03 1:56 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <51FC5478.40500@linuxtoys.org>
2013-08-03 1:19 ` Bob Smith
2013-08-03 1:56 ` Joe Perches [this message]
2013-08-03 2:35 ` Greg Kroah-Hartman
2013-08-03 18:12 ` Bob Smith
2013-08-03 22:38 ` Greg Kroah-Hartman
2013-08-04 21:54 ` Bob Smith
2013-08-04 23:19 ` Greg Kroah-Hartman
2013-08-05 23:46 ` Bob Smith
2013-08-06 9:46 ` Greg Kroah-Hartman
2013-08-07 19:02 ` Bob Smith
2013-08-07 19:27 ` Greg Kroah-Hartman
2013-08-07 19:39 ` Bob Smith
2013-08-07 19:51 ` Greg Kroah-Hartman
2013-08-07 19:54 ` Greg Kroah-Hartman
2013-08-07 21:04 ` Bob Smith
2013-08-07 21:33 ` Greg Kroah-Hartman
2013-08-08 21:23 ` Bob Smith
2013-08-09 21:52 ` Greg Kroah-Hartman
2013-08-09 22:20 ` Bob Smith
2013-08-09 22:14 ` Bob Smith
2013-08-09 23:01 ` Greg Kroah-Hartman
2013-08-09 23:35 ` Bob Smith
2013-08-09 23:46 ` Greg Kroah-Hartman
2013-08-10 20:08 ` Bob Smith
2013-08-10 20:29 ` richard -rw- weinberger
2013-08-10 20:49 ` Bob Smith
2013-08-10 21:43 ` Arnd Bergmann
2013-08-10 22:07 ` Bob Smith
2013-08-13 20:15 ` Arnd Bergmann
2013-08-07 21:28 ` Bob Smith
2013-08-07 21:40 ` Greg Kroah-Hartman
2013-08-07 21:53 ` Bob Smith
2013-08-09 21:54 ` Greg Kroah-Hartman
2013-08-09 22:51 ` Bob Smith
2013-08-09 23:04 ` Greg Kroah-Hartman
2013-08-07 21:38 ` Bob Smith
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=1375494985.2034.160.camel@joe-AO722 \
--to=joe@perches.com \
--cc=arnd@arndb.de \
--cc=bsmith@linuxtoys.org \
--cc=gregkh@linuxfoundation.org \
--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
all inboxes | Powered by JetHome®