[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20140317.212534.579591104509436501.davem@davemloft.net>
Date: Mon, 17 Mar 2014 21:25:34 -0400 (EDT)
From: David Miller <davem@...emloft.net>
To: richardcochran@...il.com
Cc: netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
ben@...adent.org.uk, christian.riesch@...cron.at,
stefan.sorensen@...ctralink.com
Subject: Re: [PATCH net-next v2 1/9] ptp: introduce programmable pins.
From: Richard Cochran <richardcochran@...il.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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists