Message ID | 20231122032518.53305-1-jiapeng.chong@linux.alibaba.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1072359vqb; Tue, 21 Nov 2023 19:25:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjpecip2w8UPHw9McOumLhRUK6mCNQNMfoChfOVa5PyPxoo4OhPAnQsrIr4p6KJywckVPk X-Received: by 2002:a17:902:9001:b0:1cf:6453:b268 with SMTP id a1-20020a170902900100b001cf6453b268mr966971plp.53.1700623535668; Tue, 21 Nov 2023 19:25:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700623535; cv=none; d=google.com; s=arc-20160816; b=RftISaH79Gm/H3ruKU+vh82Rh/886JtrVI2UuTMp+GB6UiNY9NIZFg9lvRpbS0gB+b W9rN51UQgTL0WGUSoHVcT361bOpmA9PdNNDFm0qGkS0+VIecyAU9q09vzrRtIM7/P6tT 5ez7ctAoNrtGwzVvaacswO232zGB6Ag0Pe65f19BWJBJwI0I8vjjs0IdX71mVBXfnf/c QZg4f0Q+/1KYpeECHUpU1seHB0RXnw3IBFXmQIvqsiDrcdgc5XdEmP43w/ctdTb0/1EP qcnD7MtL83/uQi5g+NmpQ7fYG5M2DkyMkmtLR77PEAvdyizqIJA7yAfur6t7w0UJFo5H dkGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=l+3TINVQZnBCy9NnOcEPayN62Lly57GvewPPxRJOTAk=; fh=gq86n0zt2vdfX3gQf7Oq24vOFRNof8sZ6S2UjtxrLMc=; b=U+8MtV5Y5z/cqXR573Amj/t6hU8aWVIg4qMM38bDEJbjiEV1ZSvYMDrcxw2hPLFUwq BJcWb3bUStvO0Jt2nmDSQaXGL4KDOwWp5ktTyq4LOGC0CPA1y6+eupFITPA4zL2xFvh0 1ABJEcX3fzEzfJ+cqiBqdexlw0TT3HXflCDfTB4xpNZtgJGpGNXqTsoq0OkxCazXVrvr pEjUxdFIAgSjTeJsjlU8VCEjKt/PB5X125LKbg0IaceugZ23p6MfnbAbj/C94P/hP+CD nNL0uT3YUUGg2iB/AzbMDIiQSByLw3DmDTo2+RWNzAFBvroZwDFlY82icza/b+nTPCOf kvRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id y12-20020a17090322cc00b001c9fb2acff5si12333062plg.526.2023.11.21.19.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 19:25:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CC0CA802658E; Tue, 21 Nov 2023 19:25:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343588AbjKVDZc (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Tue, 21 Nov 2023 22:25:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343543AbjKVDZa (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 21 Nov 2023 22:25:30 -0500 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EE9590 for <linux-kernel@vger.kernel.org>; Tue, 21 Nov 2023 19:25:26 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=jiapeng.chong@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VwuRqSm_1700623519; Received: from localhost(mailfrom:jiapeng.chong@linux.alibaba.com fp:SMTPD_---0VwuRqSm_1700623519) by smtp.aliyun-inc.com; Wed, 22 Nov 2023 11:25:24 +0800 From: Jiapeng Chong <jiapeng.chong@linux.alibaba.com> To: richard@nod.at Cc: anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net, linux-um@lists.infradead.org, linux-kernel@vger.kernel.org, Jiapeng Chong <jiapeng.chong@linux.alibaba.com>, Abaci Robot <abaci@linux.alibaba.com> Subject: [PATCH] um: Use swap() instead of open coding it Date: Wed, 22 Nov 2023 11:25:18 +0800 Message-Id: <20231122032518.53305-1-jiapeng.chong@linux.alibaba.com> X-Mailer: git-send-email 2.20.1.7.g153144c MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 21 Nov 2023 19:25:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783233024510987231 X-GMAIL-MSGID: 1783233024510987231 |
Series |
um: Use swap() instead of open coding it
|
|
Commit Message
Jiapeng Chong
Nov. 22, 2023, 3:25 a.m. UTC
Swap is a function interface that provides exchange function. To avoid
code duplication, we can use swap function.
./arch/um/os-Linux/sigio.c:81:28-29: WARNING opportunity for swap().
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=7607
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
arch/um/os-Linux/sigio.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
Comments
On Wed, 2023-11-22 at 11:25 +0800, Jiapeng Chong wrote: > Swap is a function interface that provides exchange function. To avoid > code duplication, we can use swap function. > > ./arch/um/os-Linux/sigio.c:81:28-29: WARNING opportunity for swap(). > Hm. There's already a use of swap() here in this file, but I actually think we should revert that? This is basically userspace code, not kernel code, so I don't think it should include linux headers, even if those happen to be "standalone enough" right now to work. johannes
Hi Jiapeng, kernel test robot noticed the following build errors: [auto build test ERROR on wireless-next/main] [also build test ERROR on linus/master v6.7-rc2 next-20231122] [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#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Jiapeng-Chong/um-Use-swap-instead-of-open-coding-it/20231122-113031 base: https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main patch link: https://lore.kernel.org/r/20231122032518.53305-1-jiapeng.chong%40linux.alibaba.com patch subject: [PATCH] um: Use swap() instead of open coding it config: um-randconfig-002-20231122 (https://download.01.org/0day-ci/archive/20231123/202311230408.bRL1q7pc-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231123/202311230408.bRL1q7pc-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202311230408.bRL1q7pc-lkp@intel.com/ All errors (new ones prefixed by >>): >> arch/um/os-Linux/sigio.c:80:5: error: call to undeclared function 'swap'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 80 | swap(current_poll, next_poll); | ^ arch/um/os-Linux/sigio.c:80:5: note: did you mean 'swab'? /usr/include/unistd.h:1168:13: note: 'swab' declared here 1168 | extern void swab (const void *__restrict __from, void *__restrict __to, | ^ 1 error generated. vim +/swap +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 = ¤t_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
Hi Jiapeng, kernel test robot noticed the following build errors: [auto build test ERROR on wireless-next/main] [also build test ERROR on linus/master v6.7-rc2 next-20231122] [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#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Jiapeng-Chong/um-Use-swap-instead-of-open-coding-it/20231122-113031 base: https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main patch link: https://lore.kernel.org/r/20231122032518.53305-1-jiapeng.chong%40linux.alibaba.com patch subject: [PATCH] um: Use swap() instead of open coding it config: um-randconfig-001-20231122 (https://download.01.org/0day-ci/archive/20231123/202311230538.6Fd2FqkL-lkp@intel.com/config) compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231123/202311230538.6Fd2FqkL-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202311230538.6Fd2FqkL-lkp@intel.com/ All errors (new ones prefixed by >>): >> arch/um/os-Linux/sigio.c:80:5: error: call to undeclared function 'swap'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] swap(current_poll, next_poll); ^ arch/um/os-Linux/sigio.c:80:5: note: did you mean 'swab'? /usr/include/unistd.h:1168:13: note: 'swab' declared here extern void swab (const void *__restrict __from, void *__restrict __to, ^ 1 error generated. vim +/swap +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 = ¤t_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
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 {