* [PATCH v2 0/3] ngene: Replace semaphores with mutexes
@ 2017-06-13 8:58 Binoy Jayan
2017-06-13 8:58 ` [PATCH v2 1/3] media: ngene: Replace semaphore cmd_mutex with mutex Binoy Jayan
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Binoy Jayan @ 2017-06-13 8:58 UTC (permalink / raw)
To: Binoy Jayan
Cc: linux-kernel, Arnd Bergmann, Rajendra, Mark Brown,
Mauro Carvalho Chehab, Sakari Ailus, Julia Lawall,
Michael S. Tsirkin, Cao jin, linux-media
These are a set of patches [v2] which removes semaphores from ngene.
These are part of a bigger effort to eliminate unwanted semaphores
from the linux kernel.
v1 --> v2
---------
Moved mutex_[lock/unlock] outside caller for stream_mutex
mutex_lock converted to mutex_destroy in cmd_mutex
Binoy Jayan (3):
media: ngene: Replace semaphore cmd_mutex with mutex
media: ngene: Replace semaphore stream_mutex with mutex
media: ngene: Replace semaphore i2c_switch_mutex with mutex
drivers/media/pci/ngene/ngene-core.c | 32 ++++++++++++++------------------
drivers/media/pci/ngene/ngene-i2c.c | 6 +++---
drivers/media/pci/ngene/ngene.h | 6 +++---
3 files changed, 20 insertions(+), 24 deletions(-)
--
Binoy Jayan
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] media: ngene: Replace semaphore cmd_mutex with mutex
2017-06-13 8:58 [PATCH v2 0/3] ngene: Replace semaphores with mutexes Binoy Jayan
@ 2017-06-13 8:58 ` Binoy Jayan
2017-06-13 8:58 ` [PATCH v2 2/3] media: ngene: Replace semaphore stream_mutex " Binoy Jayan
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Binoy Jayan @ 2017-06-13 8:58 UTC (permalink / raw)
To: Binoy Jayan
Cc: linux-kernel, Arnd Bergmann, Rajendra, Mark Brown,
Mauro Carvalho Chehab, Sakari Ailus, Julia Lawall,
Michael S. Tsirkin, Cao jin, linux-media
The semaphore 'cmd_mutex' is used as a simple mutex, so
it should be written as one. Also, replace down with
mutex_destroy to ensure sane state when ngene_stop is
called.
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(-)
diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
index ce69e64..eeb61eb 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_destroy(&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;
--
Binoy Jayan
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] media: ngene: Replace semaphore stream_mutex with mutex
2017-06-13 8:58 [PATCH v2 0/3] ngene: Replace semaphores with mutexes Binoy Jayan
2017-06-13 8:58 ` [PATCH v2 1/3] media: ngene: Replace semaphore cmd_mutex with mutex Binoy Jayan
@ 2017-06-13 8:58 ` Binoy Jayan
2017-06-13 8:58 ` [PATCH v2 3/3] media: ngene: Replace semaphore i2c_switch_mutex " Binoy Jayan
2017-06-13 9:49 ` [PATCH v2 0/3] ngene: Replace semaphores with mutexes Arnd Bergmann
3 siblings, 0 replies; 6+ messages in thread
From: Binoy Jayan @ 2017-06-13 8:58 UTC (permalink / raw)
To: Binoy Jayan
Cc: linux-kernel, Arnd Bergmann, Rajendra, Mark Brown,
Mauro Carvalho Chehab, Sakari Ailus, Julia Lawall,
Michael S. Tsirkin, Cao jin, linux-media
The semaphore 'stream_mutex' is used as a simple mutex, so
it should be written as one. Also moving the mutex_[lock/unlock]
to the caller as it is anyway locked at the beginning of the
callee thus avoiding repetition.
Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
---
drivers/media/pci/ngene/ngene-core.c | 18 +++++++-----------
drivers/media/pci/ngene/ngene.h | 2 +-
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
index eeb61eb..ea64901 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -560,7 +560,6 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream,
u16 BsSPI = ((stream & 1) ? 0x9800 : 0x9700);
u16 BsSDO = 0x9B00;
- down(&dev->stream_mutex);
memset(&com, 0, sizeof(com));
com.cmd.hdr.Opcode = CMD_CONTROL;
com.cmd.hdr.Length = sizeof(struct FW_STREAM_CONTROL) - 2;
@@ -586,17 +585,13 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream,
chan->State = KSSTATE_ACQUIRE;
chan->HWState = HWSTATE_STOP;
spin_unlock_irq(&chan->state_lock);
- if (ngene_command(dev, &com) < 0) {
- up(&dev->stream_mutex);
+ if (ngene_command(dev, &com) < 0)
return -1;
- }
/* clear_buffers(chan); */
flush_buffers(chan);
- up(&dev->stream_mutex);
return 0;
}
spin_unlock_irq(&chan->state_lock);
- up(&dev->stream_mutex);
return 0;
}
@@ -692,11 +687,9 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream,
chan->HWState = HWSTATE_STARTUP;
spin_unlock_irq(&chan->state_lock);
- if (ngene_command(dev, &com) < 0) {
- up(&dev->stream_mutex);
+ if (ngene_command(dev, &com) < 0)
return -1;
- }
- up(&dev->stream_mutex);
+
return 0;
}
@@ -750,8 +743,11 @@ void set_transfer(struct ngene_channel *chan, int state)
/* else printk(KERN_INFO DEVICE_NAME ": lock=%08x\n",
ngreadl(0x9310)); */
+ mutex_lock(&dev->stream_mutex);
ret = ngene_command_stream_control(dev, chan->number,
control, mode, flags);
+ mutex_unlock(&dev->stream_mutex);
+
if (!ret)
chan->running = state;
else
@@ -1347,7 +1343,7 @@ static int ngene_start(struct ngene *dev)
init_waitqueue_head(&dev->tx_wq);
init_waitqueue_head(&dev->rx_wq);
mutex_init(&dev->cmd_mutex);
- sema_init(&dev->stream_mutex, 1);
+ mutex_init(&dev->stream_mutex);
sema_init(&dev->pll_mutex, 1);
sema_init(&dev->i2c_switch_mutex, 1);
spin_lock_init(&dev->cmd_lock);
diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h
index e600b70..0dd15d6 100644
--- a/drivers/media/pci/ngene/ngene.h
+++ b/drivers/media/pci/ngene/ngene.h
@@ -763,7 +763,7 @@ struct ngene {
wait_queue_head_t cmd_wq;
int cmd_done;
struct mutex cmd_mutex;
- struct semaphore stream_mutex;
+ struct mutex stream_mutex;
struct semaphore pll_mutex;
struct semaphore i2c_switch_mutex;
int i2c_current_channel;
--
Binoy Jayan
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] media: ngene: Replace semaphore i2c_switch_mutex with mutex
2017-06-13 8:58 [PATCH v2 0/3] ngene: Replace semaphores with mutexes Binoy Jayan
2017-06-13 8:58 ` [PATCH v2 1/3] media: ngene: Replace semaphore cmd_mutex with mutex Binoy Jayan
2017-06-13 8:58 ` [PATCH v2 2/3] media: ngene: Replace semaphore stream_mutex " Binoy Jayan
@ 2017-06-13 8:58 ` Binoy Jayan
2017-06-13 9:49 ` [PATCH v2 0/3] ngene: Replace semaphores with mutexes Arnd Bergmann
3 siblings, 0 replies; 6+ messages in thread
From: Binoy Jayan @ 2017-06-13 8:58 UTC (permalink / raw)
To: Binoy Jayan
Cc: linux-kernel, Arnd Bergmann, Rajendra, Mark Brown,
Mauro Carvalho Chehab, Sakari Ailus, Julia Lawall,
Michael S. Tsirkin, Cao jin, linux-media
The semaphore 'i2c_switch_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 | 2 +-
drivers/media/pci/ngene/ngene-i2c.c | 6 +++---
drivers/media/pci/ngene/ngene.h | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
index ea64901..8c92cb7 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -1345,7 +1345,7 @@ static int ngene_start(struct ngene *dev)
mutex_init(&dev->cmd_mutex);
mutex_init(&dev->stream_mutex);
sema_init(&dev->pll_mutex, 1);
- sema_init(&dev->i2c_switch_mutex, 1);
+ mutex_init(&dev->i2c_switch_mutex);
spin_lock_init(&dev->cmd_lock);
for (i = 0; i < MAX_STREAM; i++)
spin_lock_init(&dev->channel[i].state_lock);
diff --git a/drivers/media/pci/ngene/ngene-i2c.c b/drivers/media/pci/ngene/ngene-i2c.c
index cf39fcf..fbf3635 100644
--- a/drivers/media/pci/ngene/ngene-i2c.c
+++ b/drivers/media/pci/ngene/ngene-i2c.c
@@ -118,7 +118,7 @@ static int ngene_i2c_master_xfer(struct i2c_adapter *adapter,
(struct ngene_channel *)i2c_get_adapdata(adapter);
struct ngene *dev = chan->dev;
- down(&dev->i2c_switch_mutex);
+ mutex_lock(&dev->i2c_switch_mutex);
ngene_i2c_set_bus(dev, chan->number);
if (num == 2 && msg[1].flags & I2C_M_RD && !(msg[0].flags & I2C_M_RD))
@@ -136,11 +136,11 @@ static int ngene_i2c_master_xfer(struct i2c_adapter *adapter,
msg[0].buf, msg[0].len, 0))
goto done;
- up(&dev->i2c_switch_mutex);
+ mutex_unlock(&dev->i2c_switch_mutex);
return -EIO;
done:
- up(&dev->i2c_switch_mutex);
+ mutex_unlock(&dev->i2c_switch_mutex);
return num;
}
diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h
index 0dd15d6..7c7cd21 100644
--- a/drivers/media/pci/ngene/ngene.h
+++ b/drivers/media/pci/ngene/ngene.h
@@ -765,7 +765,7 @@ struct ngene {
struct mutex cmd_mutex;
struct mutex stream_mutex;
struct semaphore pll_mutex;
- struct semaphore i2c_switch_mutex;
+ struct mutex i2c_switch_mutex;
int i2c_current_channel;
int i2c_current_bus;
spinlock_t cmd_lock;
--
Binoy Jayan
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] ngene: Replace semaphores with mutexes
2017-06-13 8:58 [PATCH v2 0/3] ngene: Replace semaphores with mutexes Binoy Jayan
` (2 preceding siblings ...)
2017-06-13 8:58 ` [PATCH v2 3/3] media: ngene: Replace semaphore i2c_switch_mutex " Binoy Jayan
@ 2017-06-13 9:49 ` Arnd Bergmann
2017-06-13 10:31 ` Binoy Jayan
3 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2017-06-13 9:49 UTC (permalink / raw)
To: Binoy Jayan
Cc: Linux Kernel Mailing List, Rajendra, Mark Brown,
Mauro Carvalho Chehab, Sakari Ailus, Julia Lawall,
Michael S. Tsirkin, Cao jin, Linux Media Mailing List
On Tue, Jun 13, 2017 at 10:58 AM, Binoy Jayan <binoy.jayan@linaro.org> wrote:
> These are a set of patches [v2] which removes semaphores from ngene.
> These are part of a bigger effort to eliminate unwanted semaphores
> from the linux kernel.
All three
Acked-by: Arnd Bergmann <arnd@arndb.de>
I already gave an Ack for one or two of the patches in the first round, but
you seem to have dropped that. When you resend a patch with an Ack,
please include that above your Signed-off-by line. (No need to resend
for an Ack otherwise, this normally gets picked up when the patch
gets applied from the list.
Arnd
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] ngene: Replace semaphores with mutexes
2017-06-13 9:49 ` [PATCH v2 0/3] ngene: Replace semaphores with mutexes Arnd Bergmann
@ 2017-06-13 10:31 ` Binoy Jayan
0 siblings, 0 replies; 6+ messages in thread
From: Binoy Jayan @ 2017-06-13 10:31 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Linux Kernel Mailing List, Rajendra, Mark Brown,
Mauro Carvalho Chehab, Sakari Ailus, Julia Lawall,
Michael S. Tsirkin, Cao jin, Linux Media Mailing List
Hi Arnd,
On 13 June 2017 at 15:19, Arnd Bergmann <arnd@arndb.de> wrote:
> On Tue, Jun 13, 2017 at 10:58 AM, Binoy Jayan <binoy.jayan@linaro.org> wrote:
>> These are a set of patches [v2] which removes semaphores from ngene.
>> These are part of a bigger effort to eliminate unwanted semaphores
>> from the linux kernel.
>
> All three
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
>
> I already gave an Ack for one or two of the patches in the first round, but
> you seem to have dropped that. When you resend a patch with an Ack,
> please include that above your Signed-off-by line. (No need to resend
> for an Ack otherwise, this normally gets picked up when the patch
> gets applied from the list.
Sorry I dropped it as there were changes in two of the patches.
But there were obvious ones anyway.
Thanks,
Binoy
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-06-13 10:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-13 8:58 [PATCH v2 0/3] ngene: Replace semaphores with mutexes Binoy Jayan
2017-06-13 8:58 ` [PATCH v2 1/3] media: ngene: Replace semaphore cmd_mutex with mutex Binoy Jayan
2017-06-13 8:58 ` [PATCH v2 2/3] media: ngene: Replace semaphore stream_mutex " Binoy Jayan
2017-06-13 8:58 ` [PATCH v2 3/3] media: ngene: Replace semaphore i2c_switch_mutex " Binoy Jayan
2017-06-13 9:49 ` [PATCH v2 0/3] ngene: Replace semaphores with mutexes Arnd Bergmann
2017-06-13 10:31 ` Binoy Jayan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).