From patchwork Thu Feb 1 15:17:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13541227 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EBC51649BE for ; Thu, 1 Feb 2024 15:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706800721; cv=none; b=iKz66CHSBnqbC3aKIoWVuQ9r4x7Iv8f3Pn17EvA5MUqmQZNGj9h5SEp6Z3cmuOQNOZhnf1c5mnbKu+qkzE8CehpTMKeHnOZKM/uZzULwhUsqKZGctaaYazckCefbGEfBWAANcVBOv/JvPDYQJ24dPCye8axie/2hBIeHpdIjPZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706800721; c=relaxed/simple; bh=8AmGOrxF5BJKtp6H6Muu441eLF+YwZwWk+YEoILDZyk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SJqws+U2ZO5WiWRnigryevYyhUOnlxI53TmmTsbejZxQNFNqGcJO/8RSmkmKsUn49oCHwRgcw8DnFRxH5LOXr1H0ya7n6mrabku2JCkoivIjL3kHBWcrLC0fTM1d3/DvPE+HXxg467XCXcDc4y3Cg6gXaAAaOSjgFiM3mpPNwak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=I3RCHi7P; arc=none smtp.client-ip=209.85.160.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I3RCHi7P" Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-218dd3fdb7cso565996fac.2 for ; Thu, 01 Feb 2024 07:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706800719; x=1707405519; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ioTtzmBOSMPWiRFt+shKVv+FPLdllL79t9aczybFkMk=; b=I3RCHi7PWdw+NXrw/8E6JREo3NWaFIvI7/53JlVV1DHNTb5PYszMrKx6yGzOZidJgw 5bCLOqlM0guCffRJdErmk5DqVLliT5n8+mPjvc+8wX9M1jcO1/r/8LIAsKE5H4/Qt1/+ k4ohqNds/c9P5MACcePW+qG8DtoxPJmEGHt6VAy67u9AQGq22rn75IojugO3sW0UiMnJ LK+crv0+zLafAVPAMPb1312s6B4FouOQnehCHkGhKF0Q/fegt9RqxoLSj38IyL4HxXi6 4Tezj74jwdq3EJWK0fITDmRvkrEUVpms5i1P2WtAXlQpHMEdYrdQHfeRWTHZLAHDnqjP G6bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706800719; x=1707405519; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ioTtzmBOSMPWiRFt+shKVv+FPLdllL79t9aczybFkMk=; b=JPTCTDudGL5qIrXHjmonJYevB/xxZvm59V82uaYHAC7L3tmGHU/d9oKTeNj5BLgy8z tLc+w7cZgPoRoHMxcZnhSvGpYpiWnH8Wyt1S2hx2puwVzWwuC75auBzF8LdVB3Q0W7Ri UJQC7t859ooENozO2CJxf6XiCqkey2nymeZHkl3QfhfSsJjQEG95ZozdiAdTEd0UwBei rx3K8gCTqtyVez7uvbm8eUS2GTZiSVSeLeaoH0CBowD804sXSZRFSrgAFk+d8IG1YTls IanBL9jksrAmgkKJJIhcSsnSX4OeT2Po7sFclrTSxziJJvIbbcx2svWhVbY2gt/ofH7h ORqw== X-Gm-Message-State: AOJu0Yxa4jH7EIknkom01BDG9MQfEo+yPzfE5gBYCqfZge8cGtTTsXt6 itOTr6596mx9/hiciz7UOJG73pifuFT7wDRtr6xUFlXS8MiArfgmJpFoNqU4 X-Google-Smtp-Source: AGHT+IF1LMNYnOH+H3NRlpYiikBWxlmrQc8KbpE4/46tQ65w54Rb4n8HPa89Zpq24LmXUpyt9jlrDw== X-Received: by 2002:a05:6871:89e:b0:218:58d5:d102 with SMTP id r30-20020a056871089e00b0021858d5d102mr4976416oaq.52.1706800718801; Thu, 01 Feb 2024 07:18:38 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id e12-20020a056870450c00b00218496d80b7sm3153326oao.29.2024.02.01.07.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:18:38 -0800 (PST) From: Denis Kenzior To: ell@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 1/2] useful: Move close cleanup into ell/util.h Date: Thu, 1 Feb 2024 09:17:33 -0600 Message-ID: <20240201151751.880279-1-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- ell/useful.h | 14 -------------- ell/util.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/ell/useful.h b/ell/useful.h index 5a4a5eba091c..8a4bf2ce70c9 100644 --- a/ell/useful.h +++ b/ell/useful.h @@ -5,11 +5,6 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include - -#include - #define align_len(len, boundary) (((len)+(boundary)-1) & ~((boundary)-1)) #define likely(x) __builtin_expect(!!(x), 1) @@ -70,15 +65,6 @@ static inline unsigned char bit_field(const unsigned char oct, #define _auto_(func) \ __AUTODESTRUCT(func) -/* Enables declaring _auto_(close) int fd = <-1 or L_TFR(open(...))>; */ -inline __attribute__((always_inline)) void close_cleanup(void *p) -{ - int fd = *(int *) p; - - if (fd >= 0) - L_TFR(close(fd)); -} - /* * Trick the compiler into thinking that var might be changed somehow by * the asm diff --git a/ell/util.h b/ell/util.h index 5dfc35c89ea6..db86bfe278ea 100644 --- a/ell/util.h +++ b/ell/util.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include @@ -314,6 +316,15 @@ const char *l_util_get_debugfs_path(void); while (__result == -1L && errno == EINTR); \ __result; })) +/* Enables declaring _auto_(close) int fd = <-1 or L_TFR(open(...))>; */ +inline __attribute__((always_inline)) void close_cleanup(void *p) +{ + int fd = *(int *) p; + + if (fd >= 0) + L_TFR(close(fd)); +} + #define _L_IN_SET_CMP(val, type, cmp, ...) __extension__ ({ \ const type __v = (val); \ const typeof(__v) __elems[] = {__VA_ARGS__}; \ From patchwork Thu Feb 1 15:17:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13541228 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6E981649C7 for ; Thu, 1 Feb 2024 15:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706800722; cv=none; b=ENp1KdQm1RvmpxQxkEl3N/99TnLgVkJT6BBpLJYf+6eis4ZVrUxefZ669intdyj24huIm3xcwHL46pKsXyd7nzftOOQVNkB4GwenEyVT6/0aeDVwVi1hNTS5r/AbJmOy4QifNjk2mT7iWz8TkwoEyCfpIM3l3PfgY3z/VUhvtXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706800722; c=relaxed/simple; bh=deiuispV5WCU4Ydn/x3JNlAwg/9aJzC3zZR+5sTlSdQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lPhtAXh26Jg5rNZ7dbMFAmubccw5zKMt21WYwpi/OJPnDaTBDKwZ7kz2JWAzG3hlSM9/21avnR3iIUNH47bmI4vgq7Q65Kpsw7L5M8VwnWlf5cTfsvE+S44o90oQin+hfNQgaok/BkQaahM/Feu8OxKlZ6wQw+m3cy1SY8lVUVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m/4g+qx9; arc=none smtp.client-ip=209.85.161.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m/4g+qx9" Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5957ede4deaso672215eaf.1 for ; Thu, 01 Feb 2024 07:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706800719; x=1707405519; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KB/gFFbQX0N0sOMvTtWqlAdzmlo+BNpSVuKL7ZoXmpE=; b=m/4g+qx9Aiy1A4uhWgpBCHs0CyHgQVWLezuh3mJVBF0EbayMXlRQvUmF2t1IQ97xyK x2ea5osfF1NQBT7EIpPpcALeOpaqLL5rvkaBbqlbEpeQV/zWsdxZv0QkdU6EfbGdxBhC 9+QTNlOp9XgKz139SeTOI03lY+57XkeAhrKtQpv3UeWBn3Q0jG5jBnWbXw03O4YHGy+C agIf0CxN1TpmmrALWs5kiMIAik8ETgTbAvUKOlmJzrQW6yanD8mXUkE5YGob83L1Il2j OmmjAXLaKpnCs6QIzDnJODhq+/m2kdTzRvRctKoKGwbXmlQ7iKC7b7LgeNl1li0N/8Zv McGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706800719; x=1707405519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KB/gFFbQX0N0sOMvTtWqlAdzmlo+BNpSVuKL7ZoXmpE=; b=wc7PJkmPT34RpzusMJgc1BRNhhCLelzmiFAHQthiI8rhjaXN5fCVC87mIT0WUdcj6x tAQ2eVtgODh8ky4tqO+JWVr8qsuQu+xlqbBurPyiyB7VCs/ZlJYc+EEYvN9Yd04BAcDv nl7FDqb4US8S71163cizfTIjOl5cY7qHI8ZvYnffNbOwtAULCNHppQDwmD3t3unmNm+s /Mrujz7LKxGUB+Pq8B0W6CA+ar5OotfHAtApUxELHyGn6Vt4N3fHxsm181a3oJLHAaj/ IkiLCdj4gRYeTGRbnAWkmF2KB8Hod16ouf1Cj0HtYFgBC8ZmdNRzM2DgUuiUM9F/4vQt jIDg== X-Gm-Message-State: AOJu0YxlNHrn73JkexUTugaxvL7ciztvglkXe6Y+R9+syCi5PAd8uAIK pkjMM8Wiv/FuC972U8EsoUCeMlOOSERaoscVVL90qLMC7fVk+iOtHB7ynh4b X-Google-Smtp-Source: AGHT+IFZc5X/SWy9+b2ULX4rsgAu7iS6RnVDucAseLKWc1W9UKe/YUSX8M+937mm5VEm6xLUdM+tWA== X-Received: by 2002:a05:6870:c387:b0:218:550b:d6a with SMTP id g7-20020a056870c38700b00218550b0d6amr5636431oao.48.1706800719565; Thu, 01 Feb 2024 07:18:39 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id e12-20020a056870450c00b00218496d80b7sm3153326oao.29.2024.02.01.07.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 07:18:39 -0800 (PST) From: Denis Kenzior To: ell@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 2/2] cleanup: Use _l_ preffix for all cleanup functions Date: Thu, 1 Feb 2024 09:17:34 -0600 Message-ID: <20240201151751.880279-2-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201151751.880279-1-denkenz@gmail.com> References: <20240201151751.880279-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Also while here, move the __AUTODESTRUCT macro to cleanup.h and prefix it with _L --- ell/cleanup.h | 5 ++++- ell/useful.h | 5 +---- ell/util.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ell/cleanup.h b/ell/cleanup.h index 337c8ad5d753..ac9f5a894b24 100644 --- a/ell/cleanup.h +++ b/ell/cleanup.h @@ -7,6 +7,9 @@ #pragma once +#define __L_AUTODESTRUCT(func) \ + __attribute((cleanup(_l_ ## func ## _cleanup))) + #define DEFINE_CLEANUP_FUNC(func) \ inline __attribute__((always_inline)) \ - void func ## _cleanup(void *p) { func(*(void **) p); } + void _l_ ## func ## _cleanup(void *p) { func(*(void **) p); } diff --git a/ell/useful.h b/ell/useful.h index 8a4bf2ce70c9..ab88f52556f5 100644 --- a/ell/useful.h +++ b/ell/useful.h @@ -59,11 +59,8 @@ static inline unsigned char bit_field(const unsigned char oct, _x / _d; \ }) -#define __AUTODESTRUCT(func) \ - __attribute((cleanup(func ## _cleanup))) - #define _auto_(func) \ - __AUTODESTRUCT(func) + __L_AUTODESTRUCT(func) /* * Trick the compiler into thinking that var might be changed somehow by diff --git a/ell/util.h b/ell/util.h index db86bfe278ea..4ae03095d013 100644 --- a/ell/util.h +++ b/ell/util.h @@ -317,7 +317,7 @@ const char *l_util_get_debugfs_path(void); __result; })) /* Enables declaring _auto_(close) int fd = <-1 or L_TFR(open(...))>; */ -inline __attribute__((always_inline)) void close_cleanup(void *p) +inline __attribute__((always_inline)) void _l_close_cleanup(void *p) { int fd = *(int *) p;