linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] um: use swap() to make code cleaner
@ 2021-11-04  6:16 davidcomponentone
  2021-11-04 11:10 ` kernel test robot
  2021-11-04 14:11 ` Anton Ivanov
  0 siblings, 2 replies; 6+ messages in thread
From: davidcomponentone @ 2021-11-04  6:16 UTC (permalink / raw)
  To: jdike
  Cc: davidcomponentone, richard, anton.ivanov, johannes.berg,
	yang.guang5, linux-um, linux-kernel, 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>
---
 arch/um/os-Linux/sigio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c
index 9e71794839e8..1eb15f3cfdc8 100644
--- a/arch/um/os-Linux/sigio.c
+++ b/arch/um/os-Linux/sigio.c
@@ -50,7 +50,7 @@ static struct pollfds all_sigio_fds;
 
 static int write_sigio_thread(void *unused)
 {
-	struct pollfds *fds, tmp;
+	struct pollfds *fds;
 	struct pollfd *p;
 	int i, n, respond_fd;
 	char c;
@@ -77,9 +77,7 @@ static int write_sigio_thread(void *unused)
 					       "write_sigio_thread : "
 					       "read on socket failed, "
 					       "err = %d\n", errno);
-				tmp = current_poll;
-				current_poll = next_poll;
-				next_poll = tmp;
+				swap(current_poll, next_poll);
 				respond_fd = sigio_private[1];
 			}
 			else {
-- 
2.30.2


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

* Re: [PATCH] um: use swap() to make code cleaner
  2021-11-04  6:16 [PATCH] um: use swap() to make code cleaner davidcomponentone
@ 2021-11-04 11:10 ` kernel test robot
  2021-11-04 14:11 ` Anton Ivanov
  1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2021-11-04 11:10 UTC (permalink / raw)
  To: davidcomponentone, jdike
  Cc: kbuild-all, davidcomponentone, richard, anton.ivanov,
	johannes.berg, yang.guang5, linux-um, linux-kernel, Zeal Robot

[-- Attachment #1: Type: text/plain, Size: 3279 bytes --]

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on rw-uml/linux-next]
[also build test ERROR on v5.15 next-20211104]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/davidcomponentone-gmail-com/um-use-swap-to-make-code-cleaner/20211104-141655
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rw/uml.git linux-next
config: um-x86_64_defconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/0daa3d13fe02d69f3d42d17d176edb0043136241
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review davidcomponentone-gmail-com/um-use-swap-to-make-code-cleaner/20211104-141655
        git checkout 0daa3d13fe02d69f3d42d17d176edb0043136241
        # save the attached .config to linux build tree
        make W=1 ARCH=um SUBARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arch/um/os-Linux/sigio.c: In function 'write_sigio_thread':
>> arch/um/os-Linux/sigio.c:80:5: error: implicit declaration of function 'swap'; did you mean 'swab'? [-Werror=implicit-function-declaration]
      80 |     swap(current_poll, next_poll);
         |     ^~~~
         |     swab
   cc1: some warnings being treated as errors


vim +80 arch/um/os-Linux/sigio.c

    50	
    51	static int write_sigio_thread(void *unused)
    52	{
    53		struct pollfds *fds;
    54		struct pollfd *p;
    55		int i, n, respond_fd;
    56		char c;
    57	
    58		os_fix_helper_signals();
    59		fds = &current_poll;
    60		while (1) {
    61			n = poll(fds->poll, fds->used, -1);
    62			if (n < 0) {
    63				if (errno == EINTR)
    64					continue;
    65				printk(UM_KERN_ERR "write_sigio_thread : poll returned "
    66				       "%d, errno = %d\n", n, errno);
    67			}
    68			for (i = 0; i < fds->used; i++) {
    69				p = &fds->poll[i];
    70				if (p->revents == 0)
    71					continue;
    72				if (p->fd == sigio_private[1]) {
    73					CATCH_EINTR(n = read(sigio_private[1], &c,
    74							     sizeof(c)));
    75					if (n != sizeof(c))
    76						printk(UM_KERN_ERR
    77						       "write_sigio_thread : "
    78						       "read on socket failed, "
    79						       "err = %d\n", errno);
  > 80					swap(current_poll, next_poll);
    81					respond_fd = sigio_private[1];
    82				}
    83				else {
    84					respond_fd = write_sigio_fds[1];
    85					fds->used--;
    86					memmove(&fds->poll[i], &fds->poll[i + 1],
    87						(fds->used - i) * sizeof(*fds->poll));
    88				}
    89	
    90				CATCH_EINTR(n = write(respond_fd, &c, sizeof(c)));
    91				if (n != sizeof(c))
    92					printk(UM_KERN_ERR "write_sigio_thread : "
    93					       "write on socket failed, err = %d\n",
    94					       errno);
    95			}
    96		}
    97	
    98		return 0;
    99	}
   100	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 9675 bytes --]

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

* Re: [PATCH] um: use swap() to make code cleaner
  2021-11-04  6:16 [PATCH] um: use swap() to make code cleaner davidcomponentone
  2021-11-04 11:10 ` kernel test robot
@ 2021-11-04 14:11 ` Anton Ivanov
  2021-11-05  6:12   ` [PATCH v2] " davidcomponentone
  1 sibling, 1 reply; 6+ messages in thread
From: Anton Ivanov @ 2021-11-04 14:11 UTC (permalink / raw)
  To: davidcomponentone, jdike
  Cc: richard, johannes.berg, yang.guang5, linux-um, linux-kernel, Zeal Robot



On 04/11/2021 06:16, 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.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
> ---
>   arch/um/os-Linux/sigio.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c
> index 9e71794839e8..1eb15f3cfdc8 100644
> --- a/arch/um/os-Linux/sigio.c
> +++ b/arch/um/os-Linux/sigio.c
> @@ -50,7 +50,7 @@ static struct pollfds all_sigio_fds;
>   
>   static int write_sigio_thread(void *unused)
>   {
> -	struct pollfds *fds, tmp;
> +	struct pollfds *fds;
>   	struct pollfd *p;
>   	int i, n, respond_fd;
>   	char c;
> @@ -77,9 +77,7 @@ static int write_sigio_thread(void *unused)
>   					       "write_sigio_thread : "
>   					       "read on socket failed, "
>   					       "err = %d\n", errno);
> -				tmp = current_poll;
> -				current_poll = next_poll;
> -				next_poll = tmp;
> +				swap(current_poll, next_poll);
>   				respond_fd = sigio_private[1];
>   			}
>   			else {
> 

You should include minmax.h for the swap macro. While there is a very significant likelihood that it will be pulled up by another something else, it is better to do that explicitly.

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

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

* [PATCH v2] um: use swap() to make code cleaner
  2021-11-04 14:11 ` Anton Ivanov
@ 2021-11-05  6:12   ` davidcomponentone
  2021-11-05  6:18     ` Yang Guang
  2021-11-05 11:30     ` David Laight
  0 siblings, 2 replies; 6+ messages in thread
From: davidcomponentone @ 2021-11-05  6:12 UTC (permalink / raw)
  To: jdike
  Cc: davidcomponentone, richard, anton.ivanov, johannes.berg,
	yang.guang5, linux-um, linux-kernel, 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>
---
 arch/um/os-Linux/sigio.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c
index 9e71794839e8..37d60e72cf26 100644
--- a/arch/um/os-Linux/sigio.c
+++ b/arch/um/os-Linux/sigio.c
@@ -3,6 +3,7 @@
  * Copyright (C) 2002 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  */
 
+#include <linux/minmax.h>
 #include <unistd.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -50,7 +51,7 @@ static struct pollfds all_sigio_fds;
 
 static int write_sigio_thread(void *unused)
 {
-	struct pollfds *fds, tmp;
+	struct pollfds *fds;
 	struct pollfd *p;
 	int i, n, respond_fd;
 	char c;
@@ -77,9 +78,7 @@ static int write_sigio_thread(void *unused)
 					       "write_sigio_thread : "
 					       "read on socket failed, "
 					       "err = %d\n", errno);
-				tmp = current_poll;
-				current_poll = next_poll;
-				next_poll = tmp;
+				swap(current_poll, next_poll);
 				respond_fd = sigio_private[1];
 			}
 			else {
-- 
2.30.2


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

* [PATCH v2] um: use swap() to make code cleaner
  2021-11-05  6:12   ` [PATCH v2] " davidcomponentone
@ 2021-11-05  6:18     ` Yang Guang
  2021-11-05 11:30     ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: Yang Guang @ 2021-11-05  6:18 UTC (permalink / raw)
  To: anton.ivanov
  Cc: davidcomponentone, jdike, johannes.berg, linux-kernel, linux-um,
	richard, yang.guang5, zealci

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>
---
 arch/um/os-Linux/sigio.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c
index 9e71794839e8..37d60e72cf26 100644
--- a/arch/um/os-Linux/sigio.c
+++ b/arch/um/os-Linux/sigio.c
@@ -3,6 +3,7 @@
  * Copyright (C) 2002 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  */
 
+#include <linux/minmax.h>
 #include <unistd.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -50,7 +51,7 @@ static struct pollfds all_sigio_fds;
 
 static int write_sigio_thread(void *unused)
 {
-	struct pollfds *fds, tmp;
+	struct pollfds *fds;
 	struct pollfd *p;
 	int i, n, respond_fd;
 	char c;
@@ -77,9 +78,7 @@ static int write_sigio_thread(void *unused)
 					       "write_sigio_thread : "
 					       "read on socket failed, "
 					       "err = %d\n", errno);
-				tmp = current_poll;
-				current_poll = next_poll;
-				next_poll = tmp;
+				swap(current_poll, next_poll);
 				respond_fd = sigio_private[1];
 			}
 			else {
-- 
2.30.2


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

* RE: [PATCH v2] um: use swap() to make code cleaner
  2021-11-05  6:12   ` [PATCH v2] " davidcomponentone
  2021-11-05  6:18     ` Yang Guang
@ 2021-11-05 11:30     ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: David Laight @ 2021-11-05 11:30 UTC (permalink / raw)
  To: 'Yang Guang', anton.ivanov
  Cc: jdike, johannes.berg, linux-kernel, linux-um, richard,
	yang.guang5, zealci

From: Yang Guang
> Sent: 05 November 2021 06:19
> 
> Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
> opencoding it.

Is there any real point to any of these patches??

If I'm reading a 'random' piece of code I now have to assume
that swap() is something that 'magically' exchanges two items.
This requires more brain-power than parsing the three lines
that do an actual swap.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

end of thread, other threads:[~2021-11-05 11:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04  6:16 [PATCH] um: use swap() to make code cleaner davidcomponentone
2021-11-04 11:10 ` kernel test robot
2021-11-04 14:11 ` Anton Ivanov
2021-11-05  6:12   ` [PATCH v2] " davidcomponentone
2021-11-05  6:18     ` Yang Guang
2021-11-05 11:30     ` David Laight

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