Message ID | 1496916298-5909-2-git-send-email-binoy.jayan@linaro.org |
---|---|
State | Accepted |
Commit | 1439cdb0315cc3f1e86cf70de22c4a90c5ac48b1 |
Headers | show |
Series | ngene: Replace semaphores with mutexes | expand |
On 8 June 2017 at 20:40, Arnd Bergmann <arnd@arndb.de> wrote: > On Thu, Jun 8, 2017 at 12:04 PM, Binoy Jayan <binoy.jayan@linaro.org> wrote: >> The semaphore 'cmd_mutex' is used as a simple mutex, so >> it should be written as one. Semaphores are going away in the future. >> >> Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org> >> --- > >> @@ -1283,7 +1283,7 @@ static int ngene_load_firm(struct ngene *dev) >> >> static void ngene_stop(struct ngene *dev) >> { >> - down(&dev->cmd_mutex); >> + mutex_lock(&dev->cmd_mutex); >> i2c_del_adapter(&(dev->channel[0].i2c_adapter)); >> i2c_del_adapter(&(dev->channel[1].i2c_adapter)); >> ngwritel(0, NGENE_INT_ENABLE); > > Are you sure about this one? There is only one mutex_lock() and > then the structure gets freed without a corresponding mutex_unlock(). > > I suspect this violates some rules of mutexes, either when compile > testing with "make C=1", or when running with lockdep enabled. > > Can we actually have a concurrently held mutex at the time we > get here? If not, using mutex_destroy() in place of the down() > may be the right answer. I noticed the missing 'up' here, but may be semaphores do not have to adhere to that rule? Thank you for pointing out that. I'll check the concurrency part. By the way why do we need mutex_destoy? To debug an aberrate condition? Thanks, Binoy
Hi Arnd, On 9 June 2017 at 16:06, Arnd Bergmann <arnd@arndb.de> wrote: >> Thank you for pointing out that. I'll check the >> concurrency part. By the way why do we need mutex_destoy? >> To debug an aberrate condition? > > At first I suspected the down() here was added for the same > purpose as a mutex_destroy: to ensure that we are in a sane > state before we free the device structure, but the way they > achieve that is completely different. > > However, if there is any way that a command may still be in > progress by the time we get to ngene_stop(), we may also > be lacking reference counting on the ngene structure here. > So far I haven't found any of those, and think the mutex_destroy() > is sufficient here as a debugging help. I've made the necessary changes. Thank you for reviewing all the patches. Regards, Binoy
diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c index ce69e64..dfbd1e0 100644 --- a/drivers/media/pci/ngene/ngene-core.c +++ b/drivers/media/pci/ngene/ngene-core.c @@ -336,9 +336,9 @@ int ngene_command(struct ngene *dev, struct ngene_command *com) { int result; - down(&dev->cmd_mutex); + mutex_lock(&dev->cmd_mutex); result = ngene_command_mutex(dev, com); - up(&dev->cmd_mutex); + mutex_unlock(&dev->cmd_mutex); return result; } @@ -1283,7 +1283,7 @@ static int ngene_load_firm(struct ngene *dev) static void ngene_stop(struct ngene *dev) { - down(&dev->cmd_mutex); + mutex_lock(&dev->cmd_mutex); i2c_del_adapter(&(dev->channel[0].i2c_adapter)); i2c_del_adapter(&(dev->channel[1].i2c_adapter)); ngwritel(0, NGENE_INT_ENABLE); @@ -1346,7 +1346,7 @@ static int ngene_start(struct ngene *dev) init_waitqueue_head(&dev->cmd_wq); init_waitqueue_head(&dev->tx_wq); init_waitqueue_head(&dev->rx_wq); - sema_init(&dev->cmd_mutex, 1); + mutex_init(&dev->cmd_mutex); sema_init(&dev->stream_mutex, 1); sema_init(&dev->pll_mutex, 1); sema_init(&dev->i2c_switch_mutex, 1); @@ -1606,10 +1606,10 @@ static void ngene_unlink(struct ngene *dev) com.in_len = 3; com.out_len = 1; - down(&dev->cmd_mutex); + mutex_lock(&dev->cmd_mutex); ngwritel(0, NGENE_INT_ENABLE); ngene_command_mutex(dev, &com); - up(&dev->cmd_mutex); + mutex_unlock(&dev->cmd_mutex); } void ngene_shutdown(struct pci_dev *pdev) diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h index 10d8f74..e600b70 100644 --- a/drivers/media/pci/ngene/ngene.h +++ b/drivers/media/pci/ngene/ngene.h @@ -762,7 +762,7 @@ struct ngene { wait_queue_head_t cmd_wq; int cmd_done; - struct semaphore cmd_mutex; + struct mutex cmd_mutex; struct semaphore stream_mutex; struct semaphore pll_mutex; struct semaphore i2c_switch_mutex;
The semaphore 'cmd_mutex' is used as a simple mutex, so it should be written as one. Semaphores are going away in the future. Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org> --- drivers/media/pci/ngene/ngene-core.c | 12 ++++++------ drivers/media/pci/ngene/ngene.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) -- Binoy Jayan