Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp179989pxy; Fri, 7 May 2021 00:17:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJXuQ5ukPFwH6+1Gs3caGmYCTeBf+dFSPfNQniR3xup+1KfEu3rAoSnR5BikPvr/QU2rpc X-Received: by 2002:a17:903:20ca:b029:ed:eb89:b441 with SMTP id i10-20020a17090320cab02900edeb89b441mr8710214plb.64.1620371842367; Fri, 07 May 2021 00:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620371842; cv=none; d=google.com; s=arc-20160816; b=HnyE0nUL//A8i/RXzFrIPHuZAk/rchcG0birtgTjIXtsVjsAqWfKku1fUV+g8uGgEU +Kj8eFf+hMPibxJZtJ7AFgXTOJ5CtG86swRygdSfy6ka4sLvk7kme0SRWDfWayNozQWQ DsOAzu6Zzx81P5HwmJ80RHC5MwlvPQEsxUcUmzwWfm8Dnu38J/cWR5DwZAf4fLuA5jzA mTnCEjYYkK82+3mBR/nPSRxJN1ws5DuS62W+OEE+EaxHxLQ5JsgXMIK3pO4zAUj1lBw6 X/00DOcoglexe/wgl3jVOyMcL2pJTTGyMEGL4S6L+cR9J8tvYXHXQ2zo/LRJx/jw7TXX DWzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=mTswA7TxkLz2ZKoHO2mvsg5Jh3THgEZWbkZV/ryZGDM=; b=N13rSndBZvq6I808FbQMAx7zu5on9o0K8uS0OFc+FnFiUISoAaUSp7Ik/G9GZMr69E vwIlFpgM27BatM3nMbuHVmHBMNcb3uL8p0HsBWFQ9W0otVrA+D3FOLv5uL0kR7XQpvt+ zccubuGPKGUTG13kYz4nOOb2+7M1winVtX2pm6tXceggZ8nLmynnGnCerJTfWhjL5fv2 BUlLYmFswCgIv2ZsU0vXeFyhWD1NlnYd34LUDQZtSeqhWdDVvozClk0aKFaKIa1XYmSG Fk4Fas/XuMB+6DVBb/k8JfJFPHRoNO5Ke5lMEjS7UlDdAW2ZwL2lh8H0J/5OydwKT5x0 IB3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JJkXQOvs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 88si5766188pjq.64.2021.05.07.00.17.09; Fri, 07 May 2021 00:17:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JJkXQOvs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233848AbhEGFZg (ORCPT + 99 others); Fri, 7 May 2021 01:25:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbhEGFZf (ORCPT ); Fri, 7 May 2021 01:25:35 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8202DC061574 for ; Thu, 6 May 2021 22:24:36 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id r9so11673654ejj.3 for ; Thu, 06 May 2021 22:24:36 -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=mTswA7TxkLz2ZKoHO2mvsg5Jh3THgEZWbkZV/ryZGDM=; b=JJkXQOvsqTer4/VMMjtYLKifk1xeYb/rsb2GOLGIgvpQeTPLESWqRlA2nvvxzXFL4Q JczCOUKcO80JXZV1fX76oHO+bAcRMW4K8aNIDCZZMOTFk8N4SuyW1wC/QzFiU4H2QeXL LprAQaRVtrulZdxek33wejDhlq3nWYbyD7c81P3XoFKdrztsdIsNKxXmCTj4InFi68vd CMExoMhaBFehXCrhO6X8i+B68SlQ9fF1d1MCmlrr48PKsIxOUdwFb5wj/fTp5qmkqJF6 UQ3xrdXUsypdIZKQW4C9HGWtOpbMlCSVftONxLD8BJB2UNJYaiYZSKapiNxsZjZGMS2D g+4w== 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=mTswA7TxkLz2ZKoHO2mvsg5Jh3THgEZWbkZV/ryZGDM=; b=Q6O/aMM+CcvP1kF6/ZTM5jVsTyNr+jPtiprOBGe8nLaPYwqWfR+8YxBpoaVfxVlyG6 gnJyNX8Uh+6nqcvOo+LVTdsrWihJAgCrTMtgi8P8h8MRUf2Qiy6Xsn6+bzm+KUElxQKS ToBs1QGTyPY8fH5yP4+QuZNaSgJ+eRHjsCdzoZfZNto0Ed/NjgR77sGTnEDMHepezsPQ 1XCYqVnrkePJaiFY93GDLoU89UYaCsS9BsntDRoBUX91zHpmhWe0iC1wwkzAhomFToa4 DD1JYLG484b52Ji5pnWVq0PYUcf0gKvoGFe/BsFXBSwKnGoTtGDP40gs4CwUwiT6UTsg xagQ== X-Gm-Message-State: AOAM5303GF/wwXhVczZlKbpUHdKusMcMIghcgRYT25wzrfiDOzvlKvw/ sLZoA7fQlkD8bRJrjqtqjw== X-Received: by 2002:a17:906:6ad0:: with SMTP id q16mr8278349ejs.286.1620365075291; Thu, 06 May 2021 22:24:35 -0700 (PDT) Received: from localhost.localdomain ([46.53.252.104]) by smtp.gmail.com with ESMTPSA id o8sm2674530ejm.18.2021.05.06.22.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 22:24:34 -0700 (PDT) Date: Fri, 7 May 2021 08:24:33 +0300 From: Alexey Dobriyan To: Linus Torvalds Cc: Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [patch 04/91] proc: save LOC in __xlate_proc_name() Message-ID: References: <20210506180126.03e1baee7ca52bedb6cc6003@linux-foundation.org> <20210507010213.V8MhqooKS%akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 06, 2021 at 07:24:36PM -0700, Linus Torvalds wrote: > On Thu, May 6, 2021 at 6:02 PM Andrew Morton wrote: > > > > From: Alexey Dobriyan > > Subject: proc: save LOC in __xlate_proc_name() > .. > > + while ((next = strchr(cp, '/'))) { > > Please don't do this. It is actually how it should be done. Kernel has such code in other places #define hlist_for_each(pos, head) \ for (pos = (head)->first; pos ; pos = pos->next) And we do check pointers for validness like this if (ptr) { } "while" loop is no different. > Yes, gcc suggests that double parentheses syntax around an assignment > to avoid warnings. I never saw this warning. I just wrote double parenth knowing the warning will be emitted. It's an old warning. > gcc is wrong, and is being completely stupid. > The proper way to avoid the "assignment in conditional" warning is to > (surprise, surprise) USE A CONDITIONAL. > > So that > > while ((next = strchr(cp, '/'))) { > > is the crazy rantings of a misguided compiler. No sane human should > ever care about some odd double parenthesis syntax. We're not writing > LISP, for chrissake. > > The proper way to write this is > > while ((next = strchr(cp, '/')) != NULL) { This NULL is redundant in the same way "if (ptr != NULL)" is redundant. Even more so in C where comparison can't be overloaded. You don't even save the parenth. > which makes sense to not just a machine, but to a human, and avoids > the whole "assignment used as a conditional" warning very naturally. > > See? Now it uses a conditional as a conditional. Doesn't that make a > whole lot more sense than the crazy ramblings of a broken machine > mind? > > I fixed it up manually, I just wanted to rant against this kind of > "mindlessly take advice from the compiler without thinking about it". Whatever-by: Alexey Dobriyan