staging: comedi: Compress return logic into one line.
PATCH 1/1 staging: comedi: Compress return logic into one line.
Simplify function return by merging assignment and return into a single line. The following coccinelle script is used to fix this issue.
@@
expression e,ret;
@@
-ret = e;
-return ret;
+return e;
--- drivers/staging/comedi/drivers.c | 3 +-- drivers/staging/comedi/drivers/cb_pcidas64.c | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-)
drivers/staging/comedi/drivers.c +1 -2
@@ -86,8 +86,7 @@ static void comedi_clear_hw_dev(struct comedi_device *dev)*/ void *comedi_alloc_devpriv (struct comedi_device *dev,size_t size) { - dev->private =kzalloc (size,GFP_KERNEL ); -return dev->private; +return kzalloc (size,GFP_KERNEL ); }EXPORT_SYMBOL_GPL (comedi_alloc_devpriv);
drivers/staging/comedi/drivers/cb_pcidas64.c +2 -6
@@ -1394,9 +1394,7 @@ static int set_ai_fifo_segment_length(struct comedi_device *dev,writew (devpriv->fifo_size_bits, devpriv->main_iobase +FIFO_SIZE_REG ); - devpriv->ai_fifo_segment_length = num_increments * increment_size; - -return devpriv->ai_fifo_segment_length; +return num_increments * increment_size; }/*
@@ -1417,9 +1415,7 @@ static int set_ai_fifo_size(struct comedi_device *dev, unsigned int num_samples)if (retval <0 )return retval; - num_samples = retval * fifo->num_segments * fifo->sample_packing_ratio; - -return num_samples; +return retval * fifo->num_segments * fifo->sample_packing_ratio; }/* query length of fifo */
Signature · 1 line
2.9.3
Review
Quoted 10 lines · Varsha Rao
Simplify function return by merging assignment and return into a single line. The following coccinelle script is used to fix this issue.
@@
expression e,ret;
@@(quoted diff) +1
-2-ret = e; -return ret; +return e;
This is too general. For example, in your first example, you remove the initialization of dev->private. It's fine to remove the initialization of a local variable that is about to go out of scope, but not to remove the initialization of a field of a structure that can be accessed after the end of the function.
julia
Quoted 57 lines
Signed-off-by Varsha Rao <[email protected]>--- drivers/staging/comedi/drivers.c | 3 +-- drivers/staging/comedi/drivers/cb_pcidas64.c | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-)drivers/staging/comedi/drivers.c +1
-2@@ -86,8 +86,7 @@ static void comedi_clear_hw_dev(struct comedi_device *dev)*/ void *comedi_alloc_devpriv (struct comedi_device *dev,size_t size) { - dev->private =kzalloc (size,GFP_KERNEL ); -return dev->private; +return kzalloc (size,GFP_KERNEL ); }EXPORT_SYMBOL_GPL (comedi_alloc_devpriv);drivers/staging/comedi/drivers/cb_pcidas64.c +2
-7@@ -1394,9 +1394,7 @@ static int set_ai_fifo_segment_length(struct comedi_device *dev,writew (devpriv->fifo_size_bits, devpriv->main_iobase +FIFO_SIZE_REG ); - devpriv->ai_fifo_segment_length = num_increments * increment_size; - -return devpriv->ai_fifo_segment_length; +return num_increments * increment_size; }/* @@ -1417,9 +1415,7 @@ static int set_ai_fifo_size(struct comedi_device *dev, unsigned int num_samples)if (retval <0 )return retval; - num_samples = retval * fifo->num_segments * fifo->sample_packing_ratio; - -return num_samples; +return retval * fifo->num_segments * fifo->sample_packing_ratio; }/* query length of fifo */ --2.9.3
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/58c53fae.4737620a.4ce3e.692c%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 12 lines · Julia Lawall
Quoted 7 lines · Varsha Rao
Simplify function return by merging assignment and return into a single line. The following coccinelle script is used to fix this issue.
@@
expression e,ret;
@@
Quoted 11 lines
Review
Quoted 3 lines
(quoted diff) +1
-2-ret = e; -return ret; +return e;This is too general. For example, in your first example, you remove the initialization of
dev->private. It's fine to remove the initialization of a local variable that is about to go out of scope, but not to remove the initialization of a field of a structure that can be accessed after the end of the function.
Yes, you are right. Sorry for it. I will send a new patch.
Thanks,
Varsha
Greg Kroah-Hartman
maintainerQuoted 22 lines · Varsha Rao
Simplify function return by merging assignment and return into a single line. The following coccinelle script is used to fix this issue.
@@
expression e,ret;
@@(quoted diff) +1
-2-ret = e; -return ret; +return e;Signed-off-by Varsha Rao <[email protected]>--- drivers/staging/comedi/drivers.c | 3 +-- drivers/staging/comedi/drivers/cb_pcidas64.c | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-)drivers/staging/comedi/drivers.c +0
-0
drivers/staging/comedi/drivers.c static void comedi_clear_hw_dev(struct comedi_device *dev) · line 89
Quoted 6 lines
drivers/staging/comedi/drivers.c +1
-2@@ -86,8 +86,7 @@ static void comedi_clear_hw_dev(struct comedi_device *dev)*/ void *comedi_alloc_devpriv (struct comedi_device *dev,size_t size) { - dev->private =kzalloc (size,GFP_KERNEL ); -return dev->private; +return kzalloc (size,GFP_KERNEL );
That broke the driver :(
Please be more careful in your review.
thanks,
greg k-h
Quoted 9 lines
That broke the driver :(
Please be more careful in your review.
I had compiled it before submitting the patch and it did not cause any
error or warning.
Is there something else to be done?
Thanks,
Varsha
Quoted 4 lines · Varsha Rao
That broke the driver :(Quoted 8 lines
�
Please be more careful in your review.
��
��� I had compiled it before submitting the patch and it did not cause any error or warning.
��� Is there something else to be done?
Yes, you need to look at the logic that you are writing/changing to determine that it is not incorrect. This is valid C code, so no build warning will happen, it's just the logic is totally wrong :)
You do see the problem, right? If not, please take the time to read it and figure out what is going on here, as it's important to know.
thanks,
greg k-h
Greg KH
maintainerQuoted 4 lines · Varsha Rao
That broke the driver :(Quoted 8 lines
�
Please be more careful in your review.
��
��� I had compiled it before submitting the patch and it did not cause any error or warning.
��� Is there something else to be done?
Yes, you need to look at the logic that you are writing/changing to determine that it is not incorrect. This is valid C code, so no build warning will happen, it's just the logic is totally wrong :)
You do see the problem, right? If not, please take the time to read it and figure out what is going on here, as it's important to know.
thanks,
greg k-h