From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1D6BC433FE for ; Sun, 30 Jan 2022 17:22:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355721AbiA3RWp (ORCPT ); Sun, 30 Jan 2022 12:22:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234764AbiA3RWn (ORCPT ); Sun, 30 Jan 2022 12:22:43 -0500 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB138C061714; Sun, 30 Jan 2022 09:22:43 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEDuP-005trj-0a; Sun, 30 Jan 2022 17:22:37 +0000 Date: Sun, 30 Jan 2022 17:22:36 +0000 From: Al Viro To: =?iso-8859-1?Q?Ma=EDra?= Canal Cc: gregkh@linuxfoundation.org, tj@kernel.org, nathan@kernel.org, ndesaulniers@google.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] seq_file: fix NULL pointer arithmetic warning Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 30, 2022 at 12:27:00PM -0300, Maíra Canal wrote: > Implement conditional logic in order to replace NULL pointer arithmetic. > > The use of NULL pointer arithmetic was pointed out by clang with the > following warning: > > fs/kernfs/file.c:128:15: warning: performing pointer arithmetic on a > null pointer has undefined behavior [-Wnull-pointer-arithmetic] > return NULL + !*ppos; > ~~~~ ^ > fs/seq_file.c:559:14: warning: performing pointer arithmetic on a > null pointer has undefined behavior [-Wnull-pointer-arithmetic] > return NULL + (*pos == 0); NAK. _If_ you want to bother with that at all, at least make it use SEQ_START_TOKEN, rather than open-coding it; what's more, kernfs_seq_start() should simply call single_start() instead of open-coding it. I.e. if (ops->seq_start) { void *next = ops->seq_start(sf, ppos); /* see the comment above kernfs_seq_stop_active() */ if (next == ERR_PTR(-ENODEV)) kernfs_seq_stop_active(sf, next); return next; } else { return single_start(sf, ppos); } and return *ppos ? NULL : SEQ_START_TOKEN; in single_start() itself.