From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 2830643D51B for ; Mon, 18 May 2026 12:48:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779108517; cv=none; b=cDt14m8d+58oyAhhTiwUDMbjXH5OIqgYCmAbf7BMC4cFZIUkI0JA2Ylkpnn9nhqSXgr5/pycejUQlYxu0de5jw+dpCB3+YcODyDWl3N5V7lBOcIzgt7PaSuL+6xVJv8mlU5neM1qG5IILi7kQbXNVcfz4AVWh2xhwUJ7NB1Spvo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779108517; c=relaxed/simple; bh=ir9awwZE8mojdaXk33IApda6a3sA6BIp9dfWav123FI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uIKt9RlJgYP2GuxZDPWU/PPY4b2DttAhPg3XCfV3nuXeiEnV5y3vMEXWX/Tbba7HWeSmBPoS6fFS91MsPgSttJKnMZBvVVYonOiRcXpT2rGEEpiD5U1VkFIaz5mhMAW4rO72dIPaKS8z2BYGzKSEiQy3jA27rQTA3Wl5DjoyAKU= 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=LzTo3F/m; arc=none smtp.client-ip=209.85.221.44 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="LzTo3F/m" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-43d7645adbdso1433101f8f.1 for ; Mon, 18 May 2026 05:48:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779108514; x=1779713314; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ex8tnMi3tAlmxYwkM3DQvhatICWsapujzOUrgVSrXo0=; b=LzTo3F/m2CgHqSzZ5lU0iUvsXsadJ4+azksDgNzEwn9u8hgsM1Pr/AduX7J8cBgOv7 sdOpsfo6VLz81fRhq062yCvjuYr9LXg43v3HL3G/d9kMyxZewWYnUxn94SZQPlG6rJGQ 41omWNJ9vD/8lSh2Zwyl/qT9H7wnSBa+Bq+Lonjqwf9AMMXPL0X51vDuFk5gldKdk7Od cx3IduBHiLj8XMWPD30Bl2hSTbjnXP1ESANatm/PNN+SmNbWlFi3Aq6wcBurfg9jfVgz Zntnw6oY6KpknKtUpG2jRRg2+SSsim1ZMvfMBBc9b+2YiPA7gVLTLyJIGRf/e6p02wZZ ViHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779108514; x=1779713314; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ex8tnMi3tAlmxYwkM3DQvhatICWsapujzOUrgVSrXo0=; b=MmUQl0RNzVcmSHIjDpZ93vfb2qYcIC7V+l+vKAsTd+rBuRv92vNH4jfoU2QbCHZ/fS YqZx/H0wnV5/buGKs+uS1mwu3d0R2AuFzSC7WhbiPKvFXHeMECMevk/Htw6qEoaum6UX 1gAL4DKsF9R0rnDLRcGNS89vQjtUkFc/0I51GkhpbUl6fQOK9U4K1MAxfNIA5Bm530HX EswWOouk07edDQxOxXQX8lI1gZQcGZGnrXPifst83Wn/L4nHZAw+pQ27+K5pLcqj7qcZ aOuUI9+nmM/gX9PMVtisg0HfZ7LdmvBYqjgc0aUsdN/OduZTUT66OEWxQyswIfEYfimJ i59w== X-Forwarded-Encrypted: i=1; AFNElJ/VsdjKAPubWGmhMAMo21t2MHFoOFuimZy/Tue6jhhue3BY0vIS/WmTx0xIgMdeDfnhq5O6N9m4KC83aQo=@vger.kernel.org X-Gm-Message-State: AOJu0YzsxTZ/5kWXj2OWsniCOk+HXoiX26Lkkg1e9yKMXXBlxMmdjP0q hofNA+yLg3Rmpi1sfBJjiE0b2xRhQ5xvlMfF8EVUSPZods7kXPS7g/n3hq3Rb+l/ X-Gm-Gg: Acq92OHfMlC5UWb85KbywutF6PuxaoBHxdEgYevsM+fBNpbeceWtaB7YYm+YWoLHqZu 7OPlRYdqz7FJjRAeTAPX0Cmvw6VKSeYf6mVWx8YT8trZAtLRd4lYXz80ey7DGqq5R3pGTFvoDLW kK9Up4JrUFrueRtBPZkGYa37cBUQHT6SE1m04Fq+WPJhuccOYCdvmhZquXpPWuA69IBBlEvDNzc qmwoegvF5Q8Xvvc/qEsBxm1ORkPTTu6vtRC94Yr5sl8NKdvhpAIXi9v8AStKi8BHbP3AvP9huWJ btd6KkeOn/bI2EkkFtM5lRIhlz7qsAStpGBQaQj375dv4fyGUHdgyYZGKch+V+d+TKUIl0PVsVQ Tx8BWER32oAkyYaSl2LEbSGxyZxPdczbwozx6xFX9T6Q8R3OwbGADr0IMMP5SzjF66BinRfCWVw c8PmccB2tYCSMSZT2h9P0NcpAhJX4XipmjBttum1//6biHZYT1E88i9Gn4MXWpe1Y59Aj08aFUk 4o= X-Received: by 2002:a05:6000:40df:b0:45d:b14b:2409 with SMTP id ffacd0b85a97d-45e5c35dd7bmr23470665f8f.2.1779108514308; Mon, 18 May 2026 05:48:34 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45d9ed30110sm40744268f8f.13.2026.05.18.05.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 05:48:33 -0700 (PDT) Date: Mon, 18 May 2026 13:48:32 +0100 From: David Laight To: Amir Goldstein Cc: Rasmus Villemoes , Miklos Szeredi , Christian Brauner , Jan Kara , Al Viro , Linus Torvalds , Nirmoy Das , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] err_ptr.h: introduce ERR_PTR_SAFE() Message-ID: <20260518134832.69853809@pumpkin> In-Reply-To: References: <20260514200129.94862-1-amir73il@gmail.com> <20260515193010.056ef472@pumpkin> <20260516094242.77d20c92@pumpkin> <87se7pdr7a.fsf@prevas.dk> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, 18 May 2026 11:52:06 +0200 Amir Goldstein wrote: > On Mon, May 18, 2026 at 11:04=E2=80=AFAM Rasmus Villemoes wrote: > > > > On Sat, May 16 2026, Amir Goldstein wrote: > > =20 > > > On Sat, May 16, 2026 at 10:42=E2=80=AFAM David Laight > > > wrote: =20 > > >> > > >> On Fri, 15 May 2026 21:26:04 +0200 > > >> Amir Goldstein wrote: > > >> =20 > > >> > On Fri, May 15, 2026 at 8:30=E2=80=AFPM David Laight > > >> > wrote: =20 > > >> > > > > >> > > On Thu, 14 May 2026 22:01:29 +0200 > > >> > > Amir Goldstein wrote: > > >> > > =20 > > >> ... =20 > > >> > > > > >> > > The object code bloat would be noticeable if this were used ever= ywhere. > > >> > > But you could make it a bit simpler: > > >> > > if (__builtin_constant_p(__e)) > > >> > > BUILD_BUG_ON(__e && !IS_ERR_VALUE(__e)); > > >> > > else if WARN_ON(__e && !IS_ERR_VALUE(__e)) > > >> > > __e =3D -MAX_ERRNO; // Or maybe -EINVAL to stop = and other boundary errors > > >> > > (void *)__e; =20 > > >> > > > >> > Yeh that's nicer thanks. =20 > > >> > > >> Actually this might be better still (or just more succinct): > > >> void *__e =3D (void *)error; > > >> BUILD_BUG_ON(!statically_true(IS_ERR_OR_NULL(__e)); =20 > > > > > > This condition is wrong but also my compiler does not evaluate > > > __builtin_constant_p(IS_ERR_OR_NULL(__e)) as true. > > > > > > This works > > > BUILD_BUG_ON(statically_true(!IS_ERR_VALUE(__e))); > > > > > > I think it is enough to statically assert on ERR_PTR(EINVAL) > > > and no need to bother with ERR_PTR(0) > > > =20 > > >> if (WARN_ON(!IS_ERR_OR_NULL(__e)) > > >> __e =3D (void *)-EINVAL; =20 > > > > > > Oh, anything but EINVAL please - the most overloaded error value > > > My choice of meaningful error value would be EFAULT =20 > > > > Could we have a dedicated "EBUG" that can be used to indicate "there's a > > bug somewhere in the kernel, we can handle it somewhat gracefully here > > by returning an error instead of BUG(). You can't do anything about it > > but report that you got -EBUG from $this_syscall", instead of > > overloading EIO, EFAULT, EINVAL or whatnot. Internally, EBUG could be a > > macro that did ({ WARN_ONCE(); -__EBUG; }) or something, so there would > > automatically be bread crumbs in dmesg if it is ever hit. =20 >=20 > How exactly would you use this EBUG() to write the graceful handling? > A bit of overengineering if you ask me. >=20 > > > > Userspace code could also benefit from having EBUG to indicate that some > > internal inconsistency has been detected. =20 >=20 > So what about >=20 > #define EBUG MAX_ERRNO >=20 > as per my suggested patch. Your are relying on there being no 'off-by-one' errors. They happen... -- David >=20 > Thanks, > Amir. >=20