From patchwork Mon Jun 19 15:41:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 110085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3103284vqr; Mon, 19 Jun 2023 09:04:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4mh8dnwsrCoEwwdWfvK+sSRShB5EoKCuZgrY47cSXZAQWYotaLTVC8HGBHBD7DFCiO1eFN X-Received: by 2002:a17:902:e810:b0:1af:e302:123 with SMTP id u16-20020a170902e81000b001afe3020123mr14978713plg.3.1687190670470; Mon, 19 Jun 2023 09:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687190670; cv=none; d=google.com; s=arc-20160816; b=HUQYOPOJjMohJhmGnNIHfh0bju774nbV0DLoSylWHma4QyS4l/akz9H+CNwYLJ2Qz4 qGIyo+zl8AvudPswShnVUfA+Izz5git+nC2sqtzO44kar/pdO5c/rF0dNt+xC9gQ5X0f WEbQN0a2rjP9Nbh+A8jX4JbmzrWwThopvCm4hcLBVOQ768Pb5vrpY/VWnFQnGeMpbV9B AdzSSKdgwNZUZ7o3xi05rP/x4Lufr47ASZf0lcQsPPbvNFBoZMYY8JTLB3vOD7vZB2Xm tYyK58dBaoiXdhmtwVQB3mnRiCIvNhI4AAEN/ADeVppcyZlDXjQi1MSv7HmOoipg0iDW 6mnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=3qKsn7nBaQVKdmcugz8npIUTnpYJf9EzjE822KSKtQk=; b=LOB7kpfohZMXpC38wgCprdNW36d7JRoZ+Yt/PkATTSK1mugUC6iFEWcl7H2kVr1kIF 8pgmMNq/qikFLE1KGKvcpXHIIwBr0aDTZHQNy7W3OyCPx8GCO3OV+rAFwmmxR5Wg/kI1 qadSC12wV2PGsHlSmCRVhM4lzafKWTqbxQ8qvmrf9+nrL6+vclvxwYF8pjGOwPN+ZgcK L5NFJwCFiDuKt4Q+pvbP0ZUf7RHwVmVvrG5NKPgXl7+5GTsAHRUaPRMFReOU/lC2ZVYp YY7GsPImHWr7I8WVv9EJDCc4ZZBaddNg2q4TgNEu8PzXGMdsh4kydT8N5JYDiUJWZmgd LVKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k20-20020a170902761400b001b3bf909420si98616pll.54.2023.06.19.09.04.16; Mon, 19 Jun 2023 09:04:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231608AbjFSPlj (ORCPT + 99 others); Mon, 19 Jun 2023 11:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231130AbjFSPli (ORCPT ); Mon, 19 Jun 2023 11:41:38 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BCC8113; Mon, 19 Jun 2023 08:41:36 -0700 (PDT) X-QQ-mid: bizesmtp75t1687189283tf03uy18 Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 19 Jun 2023 23:41:21 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: 3M0okmaRx3jbjpkri1hCtt3wapIdtdZ3mKAKL3x4ywEH+9AAkaH2L1w9F6TnS Tx+YKnNgtl1OQjDw+EgPeDa3FaWoF9IQmEUTi2AyVScB6EvSGVTGHXGnIS67XikEy6+naJo fSmO3ZxxH1j3v3ekw8Pf+fz/3Vw5y0iNtBdxY5vVPRSdvVba2yz0+IlpPxN96v8lDQ9vEY2 zEO3bvznX+ArQ0IfNCgqqXbXZ6lLhLV+/FvfQ6IuoCN3z9HLoccn/YpEDOzgZ15ObHr8ldM 6JtYrJ077RhHpSdzMd4doDetReqFvlVxWZ5HY+fXN+9H53o+TN+P/bL9iFJv+xQQb9gYLW6 Nt2EHqyX1g14gbJiAKteWKJ+DTc5ksX0Nx4cmNTluBs3O+E5h5KOoLZ47NeDSnyQVQuzXij X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11055691782021961800 From: Zhangjin Wu To: w@1wt.eu Cc: david.laight@aculab.com, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= Subject: [PATCH v4 01/10] tools/nolibc: sys.h: add a syscall return helper Date: Mon, 19 Jun 2023 23:41:18 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769147644370807701?= X-GMAIL-MSGID: =?utf-8?q?1769147644370807701?= Most of the library routines share the same syscall return logic: In general, a 0 return value indicates success. A -1 return value indicates an error, and an error number is stored in errno. [1] Let's add a __sysret() helper for the above logic to simplify the coding and shrink the code lines too. Thomas suggested to use inline function instead of macro for __sysret(). Willy suggested to make __sysret() be always inline. [1]: https://man7.org/linux/man-pages/man2/syscall.2.html Suggested-by: Willy Tarreau Link: https://lore.kernel.org/linux-riscv/ZH1+hkhiA2+ItSvX@1wt.eu/ Suggested-by: Thomas Weißschuh Link: https://lore.kernel.org/linux-riscv/ea4e7442-7223-4211-ba29-70821e907888@t-8ch.de/ Reviewed-by: Thomas Weißschuh Signed-off-by: Zhangjin Wu --- tools/include/nolibc/sys.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 856249a11890..150777207468 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -28,6 +28,16 @@ #include "errno.h" #include "types.h" +/* Syscall return helper, set errno as -ret when ret < 0 */ +static __inline__ __attribute__((unused, always_inline)) +long __sysret(long ret) +{ + if (ret < 0) { + SET_ERRNO(-ret); + ret = -1; + } + return ret; +} /* Functions in this file only describe syscalls. They're declared static so * that the compiler usually decides to inline them while still being allowed