All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: dgnc: take lock when storing value in dgnc_poll_tick
@ 2015-08-18 19:37 Salah Triki
  2015-08-19 10:21 ` Dan Carpenter
  0 siblings, 1 reply; 8+ messages in thread
From: Salah Triki @ 2015-08-18 19:37 UTC (permalink / raw)
  To: gregkh, dan.carpenter
  Cc: lidza.louina, markh, driverdev-devel, devel, salah.triki

dgnc_poll_tick is declared global, so dgnc_driver_pollrate_store needs to take
the lock dgnc_poll_lock before modifying this variable. dgnc_poll_lock is
the appropriate lock, since it is inteded for poll scheduling and dgnc_poll_tick
contains the poll rate. dgnc_poll_lock needs to be declared not static and extern
in order to be visible for dgnc_driver_pollrate_store.

Signed-off-by: Salah Triki <salah.triki@acm.org>
---
 drivers/staging/dgnc/dgnc_driver.c |  2 +-
 drivers/staging/dgnc/dgnc_driver.h |  1 +
 drivers/staging/dgnc/dgnc_sysfs.c  | 10 ++++++++--
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
index 7546aff..f03e8b3 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -64,6 +64,7 @@ static const struct file_operations dgnc_BoardFops = {
 uint			dgnc_NumBoards;
 struct dgnc_board		*dgnc_Board[MAXBOARDS];
 DEFINE_SPINLOCK(dgnc_global_lock);
+DEFINE_SPINLOCK(dgnc_poll_lock);
 uint			dgnc_Major;
 int			dgnc_poll_tick = 20;	/* Poll interval - 20 ms */
 
@@ -75,7 +76,6 @@ static struct class *dgnc_class;
 /*
  * Poller stuff
  */
-static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
 static ulong		dgnc_poll_time; /* Time of next poll */
 static uint		dgnc_poll_stop; /* Used to tell poller to stop */
 static struct timer_list dgnc_poll_timer;
diff --git a/drivers/staging/dgnc/dgnc_driver.h b/drivers/staging/dgnc/dgnc_driver.h
index 06ece51..6784d81 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -389,6 +389,7 @@ struct channel_t {
  */
 extern uint		dgnc_Major;		/* Our driver/mgmt major */
 extern int		dgnc_poll_tick;		/* Poll interval - 20 ms */
+extern spinlock_t	dgnc_poll_lock;		/* Poll scheduling lock */
 extern spinlock_t	dgnc_global_lock;	/* Driver global spinlock */
 extern uint		dgnc_NumBoards;		/* Total number of boards */
 extern struct dgnc_board	*dgnc_Board[MAXBOARDS];	/* Array of board structs */
diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c
index 44db870..dcb45f3 100644
--- a/drivers/staging/dgnc/dgnc_sysfs.c
+++ b/drivers/staging/dgnc/dgnc_sysfs.c
@@ -57,11 +57,17 @@ static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp,
 					  const char *buf, size_t count)
 {
 	int ret;
+	unsigned long flags;
 
+	spin_lock_irqsave(&dgnc_poll_lock, flags);
 	ret = sscanf(buf, "%d\n", &dgnc_poll_tick);
 	if (ret != 1)
-		return -EINVAL;
-	return count;
+		ret = -EINVAL;
+	else
+		ret = count;
+	spin_unlock_irqrestore(&dgnc_poll_lock, flags);
+
+	return ret;
 }
 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgnc_driver_pollrate_show,
 		   dgnc_driver_pollrate_store);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] staging: dgnc: take lock when storing value in dgnc_poll_tick
  2015-08-18 19:37 [PATCH] staging: dgnc: take lock when storing value in dgnc_poll_tick Salah Triki
@ 2015-08-19 10:21 ` Dan Carpenter
  2015-08-19 18:11   ` [PATCH V2] " Salah Triki
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2015-08-19 10:21 UTC (permalink / raw)
  To: Salah Triki; +Cc: devel, gregkh, driverdev-devel, lidza.louina

On Tue, Aug 18, 2015 at 08:37:21PM +0100, Salah Triki wrote:
> @@ -57,11 +57,17 @@ static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp,
>  					  const char *buf, size_t count)
>  {
>  	int ret;
> +	unsigned long flags;
>  
> +	spin_lock_irqsave(&dgnc_poll_lock, flags);
>  	ret = sscanf(buf, "%d\n", &dgnc_poll_tick);
>  	if (ret != 1)
> -		return -EINVAL;
> -	return count;
> +		ret = -EINVAL;
> +	else
> +		ret = count;
> +	spin_unlock_irqrestore(&dgnc_poll_lock, flags);
> +
> +	return ret;
>  }

Looks basically ok, but I wonder if it would be better to use a
temporary buffer for the sscanf.

	unsigned long flags;
	int tick;
	int ret;

	ret = sscanf(buf, "%d\n", &tick);
	if (ret != 1)
		return -EINVAL;

	spin_lock_irqsave(&dgnc_poll_lock, flags);
	dgnc_poll_tick = tick;
	spin_unlock_irqrestore(&dgnc_poll_lock, flags);

	return count;

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH V2] staging: dgnc: take lock when storing value in dgnc_poll_tick
  2015-08-19 10:21 ` Dan Carpenter
@ 2015-08-19 18:11   ` Salah Triki
  2015-08-19 19:36     ` Dan Carpenter
  2015-08-24 12:46     ` Sudip Mukherjee
  0 siblings, 2 replies; 8+ messages in thread
From: Salah Triki @ 2015-08-19 18:11 UTC (permalink / raw)
  To: gregkh, dan.carpenter
  Cc: lidza.louina, markh, driverdev-devel, devel, salah.triki

poll_tick is declared global, so dgnc_driver_pollrate_store needs to take
the lock dgnc_poll_lock before modifying this variable. dgnc_poll_lock is
the appropriate lock, since it is intended for poll scheduling and
dgnc_poll_tick contains the poll rate. dgnc_poll_lock needs to be declared
not static and extern in order to be visible for dgnc_driver_pollrate_store.

Signed-off-by: Salah Triki <salah.triki@acm.org>
---
 drivers/staging/dgnc/dgnc_driver.c | 2 +-
 drivers/staging/dgnc/dgnc_driver.h | 1 +
 drivers/staging/dgnc/dgnc_sysfs.c  | 9 ++++++++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
index 7546aff..f03e8b3 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -64,6 +64,7 @@ static const struct file_operations dgnc_BoardFops = {
 uint			dgnc_NumBoards;
 struct dgnc_board		*dgnc_Board[MAXBOARDS];
 DEFINE_SPINLOCK(dgnc_global_lock);
+DEFINE_SPINLOCK(dgnc_poll_lock);
 uint			dgnc_Major;
 int			dgnc_poll_tick = 20;	/* Poll interval - 20 ms */
 
@@ -75,7 +76,6 @@ static struct class *dgnc_class;
 /*
  * Poller stuff
  */
-static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
 static ulong		dgnc_poll_time; /* Time of next poll */
 static uint		dgnc_poll_stop; /* Used to tell poller to stop */
 static struct timer_list dgnc_poll_timer;
diff --git a/drivers/staging/dgnc/dgnc_driver.h b/drivers/staging/dgnc/dgnc_driver.h
index 06ece51..6784d81 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -389,6 +389,7 @@ struct channel_t {
  */
 extern uint		dgnc_Major;		/* Our driver/mgmt major */
 extern int		dgnc_poll_tick;		/* Poll interval - 20 ms */
+extern spinlock_t	dgnc_poll_lock;		/* Poll scheduling lock */
 extern spinlock_t	dgnc_global_lock;	/* Driver global spinlock */
 extern uint		dgnc_NumBoards;		/* Total number of boards */
 extern struct dgnc_board	*dgnc_Board[MAXBOARDS];	/* Array of board structs */
diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c
index 44db870..f91a36a 100644
--- a/drivers/staging/dgnc/dgnc_sysfs.c
+++ b/drivers/staging/dgnc/dgnc_sysfs.c
@@ -56,11 +56,18 @@ static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf)
 static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp,
 					  const char *buf, size_t count)
 {
+	unsigned long flags;
+	int tick;
 	int ret;
 
-	ret = sscanf(buf, "%d\n", &dgnc_poll_tick);
+	ret = sscanf(buf, "%d\n", &tick);
 	if (ret != 1)
 		return -EINVAL;
+
+	spin_lock_irqsave(&dgnc_poll_lock, flags);
+	dgnc_poll_tick = tick;
+	spin_unlock_irqstore(&dgnc_poll_lock, flags);
+
 	return count;
 }
 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgnc_driver_pollrate_show,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] staging: dgnc: take lock when storing value in dgnc_poll_tick
  2015-08-19 18:11   ` [PATCH V2] " Salah Triki
@ 2015-08-19 19:36     ` Dan Carpenter
  2015-08-19 19:44       ` Salah Triki
  2015-08-24 12:46     ` Sudip Mukherjee
  1 sibling, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2015-08-19 19:36 UTC (permalink / raw)
  To: Salah Triki; +Cc: gregkh, lidza.louina, markh, driverdev-devel, devel

On Wed, Aug 19, 2015 at 07:11:55PM +0100, Salah Triki wrote:
> poll_tick is declared global, so dgnc_driver_pollrate_store needs to take
> the lock dgnc_poll_lock before modifying this variable. dgnc_poll_lock is
> the appropriate lock, since it is intended for poll scheduling and
> dgnc_poll_tick contains the poll rate. dgnc_poll_lock needs to be declared
> not static and extern in order to be visible for dgnc_driver_pollrate_store.
> 
> Signed-off-by: Salah Triki <salah.triki@acm.org>
> ---

Looks good.

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

Greg has closed the tree because of the pending merge window so it will
take several weeks before he merges this.  No worries though.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] staging: dgnc: take lock when storing value in dgnc_poll_tick
  2015-08-19 19:36     ` Dan Carpenter
@ 2015-08-19 19:44       ` Salah Triki
  0 siblings, 0 replies; 8+ messages in thread
From: Salah Triki @ 2015-08-19 19:44 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: gregkh, driverdev-devel, devel, lidza.louina

On Wed, Aug 19, 2015 at 10:36:14PM +0300, Dan Carpenter wrote:
> On Wed, Aug 19, 2015 at 07:11:55PM +0100, Salah Triki wrote:
> > poll_tick is declared global, so dgnc_driver_pollrate_store needs to take
> > the lock dgnc_poll_lock before modifying this variable. dgnc_poll_lock is
> > the appropriate lock, since it is intended for poll scheduling and
> > dgnc_poll_tick contains the poll rate. dgnc_poll_lock needs to be declared
> > not static and extern in order to be visible for dgnc_driver_pollrate_store.
> > 
> > Signed-off-by: Salah Triki <salah.triki@acm.org>
> > ---
> 
> Looks good.
> 
> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Greg has closed the tree because of the pending merge window so it will
> take several weeks before he merges this.  No worries though.
> 
> regards,
> dan carpenter
> 

Thanx :)

best regards,
salah triki
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] staging: dgnc: take lock when storing value in dgnc_poll_tick
  2015-08-19 18:11   ` [PATCH V2] " Salah Triki
  2015-08-19 19:36     ` Dan Carpenter
@ 2015-08-24 12:46     ` Sudip Mukherjee
  2015-08-25  7:44       ` Salah Triki
  1 sibling, 1 reply; 8+ messages in thread
From: Sudip Mukherjee @ 2015-08-24 12:46 UTC (permalink / raw)
  To: Salah Triki; +Cc: devel, gregkh, driverdev-devel, dan.carpenter, lidza.louina

On Wed, Aug 19, 2015 at 07:11:55PM +0100, Salah Triki wrote:
> poll_tick is declared global, so dgnc_driver_pollrate_store needs to take
> the lock dgnc_poll_lock before modifying this variable. dgnc_poll_lock is
> the appropriate lock, since it is intended for poll scheduling and
> dgnc_poll_tick contains the poll rate. dgnc_poll_lock needs to be declared
> not static and extern in order to be visible for dgnc_driver_pollrate_store.
> 
> Signed-off-by: Salah Triki <salah.triki@acm.org>
> ---
<snip>
> +
> +	spin_lock_irqsave(&dgnc_poll_lock, flags);
> +	dgnc_poll_tick = tick;
> +	spin_unlock_irqstore(&dgnc_poll_lock, flags);
Have you build tested it?

regards
sudip
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] staging: dgnc: take lock when storing value in dgnc_poll_tick
  2015-08-24 12:46     ` Sudip Mukherjee
@ 2015-08-25  7:44       ` Salah Triki
  2015-08-25 18:55         ` Salah Triki
  0 siblings, 1 reply; 8+ messages in thread
From: Salah Triki @ 2015-08-25  7:44 UTC (permalink / raw)
  To: Sudip Mukherjee
  Cc: devel, gregkh, driverdev-devel, dan.carpenter, lidza.louina

On Mon, Aug 24, 2015 at 06:16:21PM +0530, Sudip Mukherjee wrote:
> On Wed, Aug 19, 2015 at 07:11:55PM +0100, Salah Triki wrote:
> > poll_tick is declared global, so dgnc_driver_pollrate_store needs to take
> > the lock dgnc_poll_lock before modifying this variable. dgnc_poll_lock is
> > the appropriate lock, since it is intended for poll scheduling and
> > dgnc_poll_tick contains the poll rate. dgnc_poll_lock needs to be declared
> > not static and extern in order to be visible for dgnc_driver_pollrate_store.
> > 
> > Signed-off-by: Salah Triki <salah.triki@acm.org>
> > ---
> <snip>
> > +
> > +	spin_lock_irqsave(&dgnc_poll_lock, flags);
> > +	dgnc_poll_tick = tick;
> > +	spin_unlock_irqstore(&dgnc_poll_lock, flags);
> Have you build tested it?
> 
> regards
> sudip

no

regards
--
salah triki
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH V2] staging: dgnc: take lock when storing value in dgnc_poll_tick
  2015-08-25  7:44       ` Salah Triki
@ 2015-08-25 18:55         ` Salah Triki
  0 siblings, 0 replies; 8+ messages in thread
From: Salah Triki @ 2015-08-25 18:55 UTC (permalink / raw)
  To: Sudip Mukherjee
  Cc: devel, gregkh, driverdev-devel, dan.carpenter, lidza.louina

On Tue, Aug 25, 2015 at 08:44:39AM +0100, Salah Triki wrote:
> On Mon, Aug 24, 2015 at 06:16:21PM +0530, Sudip Mukherjee wrote:
> > On Wed, Aug 19, 2015 at 07:11:55PM +0100, Salah Triki wrote:
> > > poll_tick is declared global, so dgnc_driver_pollrate_store needs to take
> > > the lock dgnc_poll_lock before modifying this variable. dgnc_poll_lock is
> > > the appropriate lock, since it is intended for poll scheduling and
> > > dgnc_poll_tick contains the poll rate. dgnc_poll_lock needs to be declared
> > > not static and extern in order to be visible for dgnc_driver_pollrate_store.
> > > 
> > > Signed-off-by: Salah Triki <salah.triki@acm.org>
> > > ---
> > <snip>
> > > +
> > > +	spin_lock_irqsave(&dgnc_poll_lock, flags);
> > > +	dgnc_poll_tick = tick;
> > > +	spin_unlock_irqstore(&dgnc_poll_lock, flags);
> > Have you build tested it?
> > 
> > regards
> > sudip
> 
> no
> 
> regards
> --
> salah triki

The patch failed to build. I will send the new version soon.

best regards
--
salah triki
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-08-25 18:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-18 19:37 [PATCH] staging: dgnc: take lock when storing value in dgnc_poll_tick Salah Triki
2015-08-19 10:21 ` Dan Carpenter
2015-08-19 18:11   ` [PATCH V2] " Salah Triki
2015-08-19 19:36     ` Dan Carpenter
2015-08-19 19:44       ` Salah Triki
2015-08-24 12:46     ` Sudip Mukherjee
2015-08-25  7:44       ` Salah Triki
2015-08-25 18:55         ` Salah Triki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.