mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Greg Howard <ghoward@sgi.com>
Cc: Andrew Morton <akpm@osdl.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Altix system controller communication driver
Date: Sat, 31 Jul 2004 10:55:13 +0100	[thread overview]
Message-ID: <20040731105513.A17256@infradead.org> (raw)
In-Reply-To: <Pine.SGI.4.58.0407301640510.4902@gallifrey.americas.sgi.com>; from ghoward@sgi.com on Fri, Jul 30, 2004 at 04:44:58PM -0500

> +config SGI_SNSC
> +	bool "SGI Altix system controller communication support"

this won't compile for non-ia64, so you need a depency here.

> +#include "snsc.h"
> +#include <linux/interrupt.h>
> +#include <linux/sched.h>
> +#include <linux/device.h>
> +#include <linux/poll.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <asm/sn/sn_sal.h>
> +#include <asm/sn/nodepda.h>

please include your private header after system headers.  But I don't
thing you need snsc.h at all, just move it's contents into snsc.c

> +
> +
> +#define SYSCTL_BASENAME	"snsc"
> +
> +#define SCDRV_BUFSZ	2048
> +
> +#ifdef SCDRV_DEBUG
> +#define DPRINTF(x...)	printk(x)
> +#else
> +#define DPRINTF(x...)	do {} while(0)
> +#endif

please use the existing pr_debug, or even dev_dbg where you have a struct
device.

> +static int scdrv_open(struct inode *, struct file *);
> +static int scdrv_release(struct inode *, struct file *);
> +static ssize_t scdrv_read(struct file *, char __user *, size_t, loff_t *);
> +static ssize_t scdrv_write(struct file *, const char __user *,
> +			   size_t, loff_t *);
> +static unsigned int scdrv_poll(struct file *, struct poll_table_struct *);
> +static irqreturn_t scdrv_interrupt(int, void *, struct pt_regs *);
> +
> +static struct file_operations scdrv_fops = {
> +	.owner =	THIS_MODULE,
> +	.read =		scdrv_read,
> +	.write =	scdrv_write,
> +	.poll =		scdrv_poll,
> +	.open =		scdrv_open,
> +	.release =	scdrv_release,
> +};

the driver would become more readable by having struct file_operations
after the actual function bodies, thus eliminating the need for additional
prototypes.

> +/*
> + * scdrv_wait
> + *
> + * Call this function to wait on one of the queues associated with an
> + * open subchannel.  Avoid races by entering this function with a held
> + * lock that protects the wait queue; don't release the lock until after
> + * we've added ourselves to the queue.
> + */
> +static inline int
> +scdrv_wait(wait_queue_head_t *waitq_head, spinlock_t *waitq_lock,
> +	   unsigned long flags, unsigned long timeout)
> +{
> +	DECLARE_WAITQUEUE(wait, current);
> +	int ret;
> +
> +	add_wait_queue(waitq_head, &wait);
> +	set_current_state(TASK_INTERRUPTIBLE);
> +	spin_unlock_irqrestore(waitq_lock, flags);
> +
> +	if (timeout) {
> +		ret = schedule_timeout(timeout);
> +	} else {
> +		schedule();
> +	}

You're always calling this with a timeout set.  Also I think the code
would be much more readable by opencoding this in the two callers.  That'd
also give you a chance to switch to prepare_wait & co.

> +static int
> +scdrv_open(struct inode *inode, struct file *file)
> +{
> +	struct sysctl_data_s *scd;
> +	struct subch_data_s *sd;
> +	int rv;
> +
> +	/* look up device info for this device file */
> +	scd = container_of(inode->i_cdev, struct sysctl_data_s, scd_cdev);
> +
> +	if (!scd) {
> +		printk("%s: no such device\n", __FUNCTION__);
> +		return -ENODEV;
> +	}

Can't ever be NULL.

> +		len = min((int) count, len);
> +		if (copy_to_user(buf, sd->sd_rb, len))
> +			return -EFAULT;

Don't you have sd->sd_rbs held here?

> +static inline void
> +scdrv_lock_all(struct subch_data_s *sd, unsigned long *flags)
> +{
> +	spin_lock_irqsave(&sd->sd_rlock, *flags);
> +	spin_lock(&sd->sd_wlock);
> +}
> +
> +static inline void
> +scdrv_unlock_all(struct subch_data_s *sd, unsigned long flags)
> +{
> +	spin_unlock(&sd->sd_wlock);
> +	spin_unlock_irqrestore(&sd->sd_rlock, flags);
> +}

It would probably be more readable without these wrappers.


  reply	other threads:[~2004-07-31  9:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-27 20:07 Greg Howard
2004-07-28 15:11 ` Jes Sorensen
2004-07-28 15:57 ` Andrew Morton
2004-07-28 18:21   ` Sam Ravnborg
2004-07-29 19:46     ` Greg Howard
2004-07-28 22:11   ` Greg Howard
2004-07-28 23:00     ` Andrew Morton
2004-07-29 19:50       ` Greg Howard
2004-07-30 21:44   ` Greg Howard
2004-07-31  9:55     ` Christoph Hellwig [this message]
2004-08-01  0:55     ` Andrew Morton
2004-08-02 11:46       ` Greg Howard

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=20040731105513.A17256@infradead.org \
    --to=hch@infradead.org \
    --cc=akpm@osdl.org \
    --cc=ghoward@sgi.com \
    --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®