linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools: iio: use swap() to make code cleaner
@ 2021-11-04  6:20 davidcomponentone
  2021-11-04 10:33 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: davidcomponentone @ 2021-11-04  6:20 UTC (permalink / raw)
  To: jic23
  Cc: davidcomponentone, lars, linux-iio, linux-kernel, Yang Guang, Zeal Robot

From: Yang Guang <yang.guang5@zte.com.cn>

Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
opencoding it.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
---
 tools/iio/iio_utils.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index aadee6d34c74..7a56c41fbded 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -290,15 +290,12 @@ int iioutils_get_param_float(float *output, const char *param_name,
 
 void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt)
 {
-	struct iio_channel_info temp;
 	int x, y;
 
 	for (x = 0; x < cnt; x++)
 		for (y = 0; y < (cnt - 1); y++)
 			if (ci_array[y].index > ci_array[y + 1].index) {
-				temp = ci_array[y + 1];
-				ci_array[y + 1] = ci_array[y];
-				ci_array[y] = temp;
+				swap(ci_array[y + 1], ci_array[y]);
 			}
 }
 
-- 
2.30.2


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

* Re: [PATCH] tools: iio: use swap() to make code cleaner
  2021-11-04  6:20 [PATCH] tools: iio: use swap() to make code cleaner davidcomponentone
@ 2021-11-04 10:33 ` Andy Shevchenko
  2021-11-04 10:36   ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2021-11-04 10:33 UTC (permalink / raw)
  To: davidcomponentone
  Cc: Jonathan Cameron, Lars-Peter Clausen, linux-iio,
	Linux Kernel Mailing List, Yang Guang, Zeal Robot

On Thu, Nov 4, 2021 at 8:21 AM <davidcomponentone@gmail.com> wrote:
>
> From: Yang Guang <yang.guang5@zte.com.cn>
>
> Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
> opencoding it.

Same as per other patches. Don't be a dump addon to the robot, think
about the code a little bit more.

>  void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt)
>  {
> -       struct iio_channel_info temp;
>         int x, y;
>
>         for (x = 0; x < cnt; x++)
>                 for (y = 0; y < (cnt - 1); y++)
>                         if (ci_array[y].index > ci_array[y + 1].index) {
> -                               temp = ci_array[y + 1];
> -                               ci_array[y + 1] = ci_array[y];
> -                               ci_array[y] = temp;
> +                               swap(ci_array[y + 1], ci_array[y]);
>                         }

Name of the function suggests it's a sort, we have the sort_r() API,
use it instead.

>  }

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] tools: iio: use swap() to make code cleaner
  2021-11-04 10:33 ` Andy Shevchenko
@ 2021-11-04 10:36   ` Andy Shevchenko
  2021-11-14 16:05     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2021-11-04 10:36 UTC (permalink / raw)
  To: davidcomponentone
  Cc: Jonathan Cameron, Lars-Peter Clausen, linux-iio,
	Linux Kernel Mailing List, Yang Guang, Zeal Robot

On Thu, Nov 4, 2021 at 12:33 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Thu, Nov 4, 2021 at 8:21 AM <davidcomponentone@gmail.com> wrote:

> > Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
> > opencoding it.
>
> Same as per other patches. Don't be a dump addon to the robot, think
> about the code a little bit more.
>
> >  void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt)
> >  {
> > -       struct iio_channel_info temp;
> >         int x, y;
> >
> >         for (x = 0; x < cnt; x++)
> >                 for (y = 0; y < (cnt - 1); y++)
> >                         if (ci_array[y].index > ci_array[y + 1].index) {
> > -                               temp = ci_array[y + 1];
> > -                               ci_array[y + 1] = ci_array[y];
> > -                               ci_array[y] = temp;
> > +                               swap(ci_array[y + 1], ci_array[y]);
> >                         }
>
> Name of the function suggests it's a sort, we have the sort_r() API,
> use it instead.

Ah, it's the tools folder...
Anyway, the first part of the comment stays valid for all your contribution.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] tools: iio: use swap() to make code cleaner
  2021-11-04 10:36   ` Andy Shevchenko
@ 2021-11-14 16:05     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2021-11-14 16:05 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: davidcomponentone, Lars-Peter Clausen, linux-iio,
	Linux Kernel Mailing List, Yang Guang, Zeal Robot

On Thu, 4 Nov 2021 12:36:52 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Thu, Nov 4, 2021 at 12:33 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Thu, Nov 4, 2021 at 8:21 AM <davidcomponentone@gmail.com> wrote:  
> 
> > > Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
> > > opencoding it.  
> >
> > Same as per other patches. Don't be a dump addon to the robot, think
> > about the code a little bit more.
> >  
> > >  void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt)
> > >  {
> > > -       struct iio_channel_info temp;
> > >         int x, y;
> > >
> > >         for (x = 0; x < cnt; x++)
> > >                 for (y = 0; y < (cnt - 1); y++)
> > >                         if (ci_array[y].index > ci_array[y + 1].index) {
> > > -                               temp = ci_array[y + 1];
> > > -                               ci_array[y + 1] = ci_array[y];
> > > -                               ci_array[y] = temp;
> > > +                               swap(ci_array[y + 1], ci_array[y]);
> > >                         }  
> >
> > Name of the function suggests it's a sort, we have the sort_r() API,
> > use it instead.  
> 
> Ah, it's the tools folder...
> Anyway, the first part of the comment stays valid for all your contribution.
> 

Also check this builds as it doesn't for me precisely because this is in tools and
hence should be using uapi includes only.  Maybe there is one going in for this
during the merge window but it's not in my tree yet at least.

Jonathan



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

end of thread, other threads:[~2021-11-14 16:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04  6:20 [PATCH] tools: iio: use swap() to make code cleaner davidcomponentone
2021-11-04 10:33 ` Andy Shevchenko
2021-11-04 10:36   ` Andy Shevchenko
2021-11-14 16:05     ` 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).