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 X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82388C4707F for ; Thu, 27 May 2021 15:32:25 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2F604613B6 for ; Thu, 27 May 2021 15:32:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F604613B6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kroah.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1lmHzg-0001bT-9l; Thu, 27 May 2021 11:32:20 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1lmHzd-0001bJ-Ij for kernelnewbies@kernelnewbies.org; Thu, 27 May 2021 11:32:17 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 11B69C97; Thu, 27 May 2021 11:32:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 27 May 2021 11:32:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=O3FmHbtVR/xnaqSuHgMfXWTa5qy YD/JXoWBnVecQgWQ=; b=pmbCFX3kKMeOKpGtHHE1fxpCdiDJ4YJbmmeYgmQyUR8 Hf/+oFb0fJZ9j4kArUcG0Z9+ZiRv8dLom/WG3Z7DCsbAbm2HQhRSb0xE/YSru1ut 2mEwEjf27j38xQw1jGpZ4Dl4iBFTrqiInJBLLCNONV9zJtal03Z8sGtkMPzfg6L8 PMJKW/5xvmNCvdXtLBnXX3qCnFFL/zwojeftl0RqHwtlT0iNGotA7d02FN30ybL6 4UGYUGQo6ane6lCixuGdcaMpZQGJP8F3NPA8zOToIz1q+Ldw9tuIhdjzccfTYt7h hb+s6v6G+48y4RjnmI8K7WzEEBh5KsTZyoM/UmGQDWA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=O3FmHb tVR/xnaqSuHgMfXWTa5qyYD/JXoWBnVecQgWQ=; b=dkdyLNY2Y4KQwCf1bZ4IaL CX0+hlCXH85Q2jzq3xIvbif6+HwKeXM1zHhBp/IBo7fzot91C/nlVwYk9447qZdL 0/qUGp1CSHnP+GWcIUsTQmvmuq8DxqPequdlXfJnzGtp2DO2YmqYTmzxbM3hbUBE oRYMDM77goZDdUr6XOKII/jW/oUSMOGjue6tI6dUNRrecGHRQOO3+Gg1U1mwlBEw Coo9z4j3GwuH4NePgRY7DksJTs9VYPQ3GtoK60n4J8u4RaFbdj5c2pfB10W/dciO ZmNppiKz5FN8garCZB1Hi/7ZOk/TJOoubjZ4eCnog1LZqX8RO98iAtI08OVdRSFg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdekhedgledvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesthdtre dttddtvdenucfhrhhomhepifhrvghgucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheq necuggftrfgrthhtvghrnhepveeuheejgfffgfeivddukedvkedtleelleeghfeljeeiue eggeevueduudekvdetnecukfhppeekfedrkeeirdejgedrieegnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrvghgsehkrhhorghhrdgtoh hm X-ME-Proxy: Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 27 May 2021 11:32:13 -0400 (EDT) Date: Thu, 27 May 2021 17:32:11 +0200 From: Greg KH To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: Re: Performing pointer arithmetic on a null pointer? Message-ID: References: <20210527151443.GA138263@hyeyoo> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210527151443.GA138263@hyeyoo> Cc: kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org On Fri, May 28, 2021 at 12:14:43AM +0900, Hyeonggon Yoo wrote: > Hello, I was compiling kernel with make CC=clang-10 W=1 -s > > there are some places that compiler complains about > pointer arithmetic like below.it says it's undefined behavior. > > is it just OK to use UBs like this (I hope it's not), > or am I missing something? > > fs/kernfs/file.c:128:15: warning: performing pointer arithmetic on > a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > return NULL + !*ppos; Should work just fine, what problems have you found with that code? Also happens in a few other places in the vfs layer. Tricky code, but it works as pointer math is valid C code :) thanks, greg k-h _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies