netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: richardcochran@gmail.com
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH 1/3] ptp: Added a brand new class driver for ptp clocks.
Date: Tue, 27 Apr 2010 13:07:21 -0700 (PDT)	[thread overview]
Message-ID: <20100427.130721.137847511.davem@davemloft.net> (raw)
In-Reply-To: <20100427091405.GA5098@riccoc20.at.omicron.at>

From: Richard Cochran <richardcochran@gmail.com>
Date: Tue, 27 Apr 2010 11:14:05 +0200

> +struct ptp_clock {
> +	struct cdev cdev;
> +	struct device *dev;
> +	struct ptp_clock_info *info;
> +	dev_t devid;
> +	int index; /* index into clocks[], also the minor number */
> +	struct semaphore mux; /* one process at a time on a device */
> +};

A mutex works just as well and is preferable to a semaphore.

> +/* private globals */
> +
> +static const struct file_operations ptp_fops;
> +static dev_t ptp_devt;
> +static struct class *ptp_class;
> +struct ptp_clock *clocks[PTP_MAX_CLOCKS];
> +DEFINE_SPINLOCK(clocks_lock);

The clocks[] table is not protected by any mutual exclusion in the
unregister method, it needs at least a spinlock or similar.  Probably
clocks_lock was meant to be used for this purpose.

Also, having arbitray limits like PTP_MAX_CLOCKS and a linear scan
when registering or unregistering is suboptimal.

Even if we're not expecting to have many of these things, use linux/list.h
list to manage these things.

In fact, if you keep them in a list you don't need to look them up at
all during at least unregister, you can return the real "struct
ptp_clock *" as an opaque ERR_PTR() back to the caller on register and
on unregister you can just list_del() on it.

Don't expose the layout of struct ptp_clock to the users, you don't have
do.  Just:

struct ptp_clock;

in the exported header file, and then you can return "struct ptp_clock *'
from ptp_clock_register() just fine.


  reply	other threads:[~2010-04-27 20:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-27  9:14 [PATCH 1/3] ptp: Added a brand new class driver for ptp clocks Richard Cochran
2010-04-27 20:07 ` David Miller [this message]
2010-04-27 22:32 ` Randy Dunlap
2010-04-28  6:08   ` Richard Cochran
2010-04-28 15:45     ` Randy Dunlap
  -- strict thread matches above, loose matches on Subject: below --
2010-04-29  9:19 Richard Cochran
2010-04-30 17:58 ` Wolfgang Grandegger
2010-05-01 14:08   ` Richard Cochran
2010-05-01 14:09     ` Wolfgang Grandegger
2010-05-02 10:50 ` Wolfgang Grandegger
2010-05-03 10:07   ` Richard Cochran
2010-05-04  7:57     ` Wolfgang Grandegger

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=20100427.130721.137847511.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).