lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 27 Apr 2010 13:07:21 -0700 (PDT)
From:	David Miller <davem@...emloft.net>
To:	richardcochran@...il.com
Cc:	netdev@...r.kernel.org
Subject: Re: [PATCH 1/3] ptp: Added a brand new class driver for ptp clocks.

From: Richard Cochran <richardcochran@...il.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.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ