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=0.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,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 F2E86C47089 for ; Thu, 27 May 2021 15:50:02 +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 81DF8610FC for ; Thu, 27 May 2021 15:50:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81DF8610FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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 1lmIGZ-0003b7-Lf; Thu, 27 May 2021 11:49:47 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from <42.hyeyoo@gmail.com>) id 1lmIGX-0003az-V5 for kernelnewbies@kernelnewbies.org; Thu, 27 May 2021 11:49:45 -0400 Received: by mail-pf1-x430.google.com with SMTP id y202so893272pfc.6 for ; Thu, 27 May 2021 08:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=zRhEUbc3vvFtwlgJymCBh4PaEuHTcwH/WNUr1ZU2igE=; b=lrsBy7o19dzUeFK3anbbUL2rjXhna2AwF5vaPcAj19oyv+MI8QxTfGi+V7m+TQ73Yu jb7NOMQCxeDd2HdbW2GIg/WE3dJJSXZ0xJO3/O5UplLLpxC1HNYmmDkz0UEmfXM8ZIvs IHOJwncL3fJN7f+kFvlGa3pu+wwVOHQOnmE9KbChY4oHeT4komTw8OQPfpCe3PPGFmLL vSjGAl+KxK0JM3QE8xPh7WQEmyp44eXsF99YhgbqOCq8SDx5M1abLaT9MlBVECJh44vT Fg2JLg/f1Ukd3AEefXK5+uUe5+IYVmXWHnC+VsMGAuVYuGV23Xo9491HuT2v3nhWLIOv jPrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zRhEUbc3vvFtwlgJymCBh4PaEuHTcwH/WNUr1ZU2igE=; b=p9mchVQrL5BdgbLvEtrKh8AZD+BJqAsi23s/Ak6Yn1ERSuKNZr+WUhCVGNtC+PwXvi ZsUspKC/O7+Eszrhl5PWZPXIZDaastw3p+sesD0UUyB6d7IsVB7eNsfQIHhAcnXFhVEn YecrWqF2OTbGXfekJJRAMVABZsL1lMMA25ZLPtfg7w+pkNXk3Zg0SLzGGqaVutLY1pq4 WyqZpLGSWB6L4ZdjQ+GV6cof27ZHKeEpdDHxkLzhoFMX2OloN5dL09CS9XwkZMbRtyiG ojicSsSbyLRXf2tALIq/1Q98uDnmZMzsjcEhYZTz1//zYtLa1/LCgfPlSs/pInC7dMJP lHqw== X-Gm-Message-State: AOAM531CklKq4WgTBGTAR84XF7JazJQtjV5r6pSx9cQrVSwpRpjKd0l8 tHV+VG+uCmKCvFo02bA/fY0= X-Google-Smtp-Source: ABdhPJzAqQebKyO5LQ3uw2VQwG4Qzw1kUbRgsr1bp6H1b2Gq5W9Aq+URVmm7y9YXj/JitzFhp4hhWg== X-Received: by 2002:a05:6a00:14cb:b029:2be:1466:5a28 with SMTP id w11-20020a056a0014cbb02902be14665a28mr4201505pfu.55.1622130584812; Thu, 27 May 2021 08:49:44 -0700 (PDT) Received: from hyeyoo ([183.99.11.150]) by smtp.gmail.com with ESMTPSA id gb14sm2313699pjb.57.2021.05.27.08.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 08:49:44 -0700 (PDT) Date: Fri, 28 May 2021 00:49:39 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Greg KH Subject: Re: Performing pointer arithmetic on a null pointer? Message-ID: <20210527154939.GA140035@hyeyoo> References: <20210527151443.GA138263@hyeyoo> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 Thu, May 27, 2021 at 05:32:11PM +0200, Greg KH wrote: > 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? > Hello Greg. Yeah, that should work fine. I just wanted to understand warning that clang says! > Also happens in a few other places in the vfs layer. Tricky code, but > it works as pointer math is valid C code :) I'm searching about pointer arithmetic. Documents say that pointer math on void pointer (as NULL is void pointer) is illegal by C standards. (I can be missing something!) if above is true,then is it OK because it's valid on gcc and clang? Thanks, Hyeonggon _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies