lkml.org 
[lkml]   [2014]   [Mar]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH net-next v2 1/9] ptp: introduce programmable pins.
From
From: Richard Cochran <richardcochran@gmail.com>
Date: Sun, 16 Mar 2014 14:29:22 +0100

> + /* Check to see if any other pin previously had this function. */
> + if (mutex_lock_interruptible(&ptp->pincfg_mux))
> + return -ERESTARTSYS;
> + for (i = 0; i < info->n_pins; i++) {
> + if (info->pin_config[i].func == func &&
> + info->pin_config[i].chan == chan) {
> + pin1 = &info->pin_config[i];
> + break;
> + }
> + }
> + mutex_unlock(&ptp->pincfg_mux);
...
> + if (mutex_lock_interruptible(&ptp->pincfg_mux))
> + return -ERESTARTSYS;
> + pin2->func = func;
> + pin2->chan = chan;
> + if (pin1) {
> + pin1->func = PTP_PF_NONE;
> + pin1->chan = 0;
> + }
> + mutex_unlock(&ptp->pincfg_mux);
> +
> + return 0;

This locking seems unnecessarily complex to me. You should be able to
do the stateless sanity checks, take the mutex, then do all of the
rest of the operations until the end of the function before
dropping the lock.

So just take the lock once over the operations that need it.


\
 
 \ /
  Last update: 2014-03-18 02:41    [W:0.093 / U:3.360 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site