Query on lock protection in random number driver

From: Nikanth Karthikesan
Date: Fri Jan 11 2008 - 06:04:50 EST


A query on locks used to protect entropy_store

struct entropy_store {
/* mostly-read data: */
struct poolinfo *poolinfo;
__u32 *pool;
const char *name;
int limit;
struct entropy_store *pull;

/* read-write data: */
spinlock_t lock ____cacheline_aligned_in_smp;
unsigned add_ptr;
int entropy_count;
int input_rotate;
};

Is this lock meant to protect all the data within the structure?
The lock is being taken whenever entropy_count is modified, but it is
not so when it is read, see random_poll(), random_read(). Either it
should be lock protected or made as atomic_t, right?

Also the globals random_read_wakeup_thresh and
random_write_wakeup_thresh are not at all protected by any locks! Why
locks are not needed for these?

Sorry, if that was a stupid question.

Thanks
Nikanth Karthikesan


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/