linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: triggers: Make trigger ops structure explicitly non optional.
@ 2016-05-14 17:42 Jonathan Cameron
  2016-05-29 14:00 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Cameron @ 2016-05-14 17:42 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

This structure has not been optional for a long time (if ever) but the
code implies that it is.  As we then use it later in a fashion that would
crash if it was infact NULL, gcc may well have optimized all these tests
out anyway.  However, it's inconsistent so fix it up by removing unnecessary
checkes.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/iio/industrialio-trigger.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index ae2806aafb72..672911293987 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -68,6 +68,10 @@ int iio_trigger_register(struct iio_trigger *trig_info)
 {
 	int ret;
 
+	/* trig_info->ops is required for the module member */
+	if (!trig_info->ops)
+		return -EINVAL;
+
 	trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL);
 	if (trig_info->id < 0)
 		return trig_info->id;
@@ -164,8 +168,7 @@ EXPORT_SYMBOL(iio_trigger_poll_chained);
 
 void iio_trigger_notify_done(struct iio_trigger *trig)
 {
-	if (atomic_dec_and_test(&trig->use_count) && trig->ops &&
-		trig->ops->try_reenable)
+	if (atomic_dec_and_test(&trig->use_count) && trig->ops->try_reenable)
 		if (trig->ops->try_reenable(trig))
 			/* Missed an interrupt so launch new poll now */
 			iio_trigger_poll(trig);
@@ -219,7 +222,7 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
 		return ret;
 	}
 
-	if (trig->ops && trig->ops->set_trigger_state && notinuse) {
+	if (trig->ops->set_trigger_state && notinuse) {
 		ret = trig->ops->set_trigger_state(trig, true);
 		if (ret < 0)
 			module_put(pf->indio_dev->info->driver_module);
@@ -236,7 +239,7 @@ static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
 		= (bitmap_weight(trig->pool,
 				 CONFIG_IIO_CONSUMERS_PER_TRIGGER)
 		   == 1);
-	if (trig->ops && trig->ops->set_trigger_state && no_other_users) {
+	if (trig->ops->set_trigger_state && no_other_users) {
 		ret = trig->ops->set_trigger_state(trig, false);
 		if (ret)
 			return ret;
@@ -358,7 +361,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
 			return ret;
 	}
 
-	if (trig && trig->ops && trig->ops->validate_device) {
+	if (trig && trig->ops->validate_device) {
 		ret = trig->ops->validate_device(trig, indio_dev);
 		if (ret)
 			return ret;
-- 
2.8.2


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

* Re: [PATCH] iio: triggers: Make trigger ops structure explicitly non optional.
  2016-05-14 17:42 [PATCH] iio: triggers: Make trigger ops structure explicitly non optional Jonathan Cameron
@ 2016-05-29 14:00 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2016-05-29 14:00 UTC (permalink / raw)
  To: linux-iio, Dan Carpenter

On 14/05/16 18:42, Jonathan Cameron wrote:
> This structure has not been optional for a long time (if ever) but the
> code implies that it is.  As we then use it later in a fashion that would
> crash if it was infact NULL, gcc may well have optimized all these tests
> out anyway.  However, it's inconsistent so fix it up by removing unnecessary
> checkes.
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
As this is trivial, an no one seems to care - applied to the togreg branch
of iio.git with some of the terrible spelling above corrected and the
reference to gcc optimizing the tests out removed (as it is specifically
prevented from doing so).

Jonathan
> ---
>  drivers/iio/industrialio-trigger.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
> index ae2806aafb72..672911293987 100644
> --- a/drivers/iio/industrialio-trigger.c
> +++ b/drivers/iio/industrialio-trigger.c
> @@ -68,6 +68,10 @@ int iio_trigger_register(struct iio_trigger *trig_info)
>  {
>  	int ret;
>  
> +	/* trig_info->ops is required for the module member */
> +	if (!trig_info->ops)
> +		return -EINVAL;
> +
>  	trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL);
>  	if (trig_info->id < 0)
>  		return trig_info->id;
> @@ -164,8 +168,7 @@ EXPORT_SYMBOL(iio_trigger_poll_chained);
>  
>  void iio_trigger_notify_done(struct iio_trigger *trig)
>  {
> -	if (atomic_dec_and_test(&trig->use_count) && trig->ops &&
> -		trig->ops->try_reenable)
> +	if (atomic_dec_and_test(&trig->use_count) && trig->ops->try_reenable)
>  		if (trig->ops->try_reenable(trig))
>  			/* Missed an interrupt so launch new poll now */
>  			iio_trigger_poll(trig);
> @@ -219,7 +222,7 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
>  		return ret;
>  	}
>  
> -	if (trig->ops && trig->ops->set_trigger_state && notinuse) {
> +	if (trig->ops->set_trigger_state && notinuse) {
>  		ret = trig->ops->set_trigger_state(trig, true);
>  		if (ret < 0)
>  			module_put(pf->indio_dev->info->driver_module);
> @@ -236,7 +239,7 @@ static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
>  		= (bitmap_weight(trig->pool,
>  				 CONFIG_IIO_CONSUMERS_PER_TRIGGER)
>  		   == 1);
> -	if (trig->ops && trig->ops->set_trigger_state && no_other_users) {
> +	if (trig->ops->set_trigger_state && no_other_users) {
>  		ret = trig->ops->set_trigger_state(trig, false);
>  		if (ret)
>  			return ret;
> @@ -358,7 +361,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
>  			return ret;
>  	}
>  
> -	if (trig && trig->ops && trig->ops->validate_device) {
> +	if (trig && trig->ops->validate_device) {
>  		ret = trig->ops->validate_device(trig, indio_dev);
>  		if (ret)
>  			return ret;
> 


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

end of thread, other threads:[~2016-05-29 14:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-14 17:42 [PATCH] iio: triggers: Make trigger ops structure explicitly non optional Jonathan Cameron
2016-05-29 14:00 ` Jonathan Cameron

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).