From patchwork Wed Jun 28 13:08:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13295777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF284EB64D7 for ; Wed, 28 Jun 2023 13:11:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1zzS6FphEP339tdpWyncwZG0VDfIBR/q7QCF5/S0Y+g=; b=zWUIoF4gdiKNoL nLidWCb4RD/sluj8oRuqKOW76aXdA6/u31TjDt2F6x6ItPOl0Af3Et3NvvdVSC67gXbQ9o4s0HQsK vp26VcMgftnG1oiTZTjd20LAoCqIIW3pZZi9DZnoKpLZG6Tn6R/X2j6sr+r9PFtIyohGvU0zh+BE6 kp8abg2uyXDYkopWbbMkmIqs6iBY144wOGOPq3QlbAEhYy8xMe3aPfnuXK2KFxPiNvjm7PSyy7DDZ Op4NNH9gcTRJqLIh8W6g+1PkWCCr6LguHilEiM84lq6F7O8S6llTzn4ENMnVVdWDO93lky1jiIFoT NCI6KADOJBiJG0nXvLVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qEUwn-00FjAC-0G; Wed, 28 Jun 2023 13:11:01 +0000 Received: from bg4.exmail.qq.com ([43.155.67.158]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qEUwk-00Fj8u-29 for linux-riscv@lists.infradead.org; Wed, 28 Jun 2023 13:11:00 +0000 X-QQ-mid: bizesmtp81t1687957840tk05w25f Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 28 Jun 2023 21:10:38 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: 3M0okmaRx3izmkUOsSxg9uIUu5hu7sXFhGMVn/F21TZKgQ+LTXI715mV+znqg V0FT8m4j5DU0uhm6jSBfO1u4rd7ypCrgSxJ91A3DlKLEueKsMfbTPPs+P9mJAzgNVumAW9U QkEQK3DazjlmxzOw8p068gfMxLkBWHbXFdbP/MVamr2vOlwQG9sNOE1r6D9eod+n8miz9Mk qH26SCAVQRROGIpcJ5YabBf38Pf4XN/b8ImH1ko0hkIy/ANWUjXjd3rcxdpp8bzl3nTjxt4 /eu8Nz4NkPabuRpc5kBjSj7f6YL1B8AiP7pvmV6zn0pBlRyQemBwh60oA6IjG2HfjjdnX3N n38Lno9VJXoOQHtJmlyr9DM9Zvh9zrl+PAfzsaANOHi+Dmo3wsu6GmpGjn/c6JhUUagGQGB X-QQ-GoodBg: 0 X-BIZMAIL-ID: 17494817763370749656 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, david.laight@aculab.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Subject: [PATCH v5 01/14] tools/nolibc: sys.h: add a syscall return helper Date: Wed, 28 Jun 2023 21:08:32 +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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230628_061059_012736_DB3A8C7E X-CRM114-Status: GOOD ( 10.89 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 5464f93e863e..097eef88cf7e 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