From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB26720EB; Wed, 27 Dec 2023 00:35:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dxGB0zE3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07299C433C7; Wed, 27 Dec 2023 00:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703637300; bh=QQSzTEKVkjhzMRUNMGeszGHif36iIyhtPSxVUIgASzk=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=dxGB0zE3RjIgHayBFc1uA1yap6INDB3FVNo1Zq0h5lm3KiTYy/oY3FDpRKh3OktVp 1rzTAD+osz5VIGcyTeX4+WCu9+/OWgUXBwBWF5glUzWHm8r1cnMF9s1CsIJM9+fyJf yP/BmVVu8ZPUHSOtpCuXk4qLP249+JDCJeicsx16rLCXaPPmus4bxOBxMhlWkxR6wn 5h7I4aIZI7di/1HaZt8L7y7AlisOzxJWK4eLiDp3F2its93Tw3/zsZaKiCT3sJuGuH 3PS8ev+J7PgRTHCHVTXaHW7LmYseCUpgjJvZsx+FjUrxPe53+u9WKb6Pbooo2oFI42 XXqPgrrjPqb7w== Date: Tue, 26 Dec 2023 18:34:58 -0600 From: Bjorn Helgaas To: Shin'ichiro Kawasaki Cc: platform-driver-x86@vger.kernel.org, Hans de Goede , Ilpo =?utf-8?B?SsOkcnZpbmVu?= , Andy Shevchenko , Lukas Wunner , linux-pci@vger.kernel.org, linux-i2c@vger.kernel.org Subject: Re: [PATCH v3] platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe Message-ID: <20231227003458.GA1485669@bhelgaas> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231225092656.2153894-1-shinichiro.kawasaki@wdc.com> On Mon, Dec 25, 2023 at 06:26:56PM +0900, Shin'ichiro Kawasaki wrote: > ... > +static int p2sb_valid_resource(struct resource *res) > +{ > + return res->flags ? 0 : -ENOENT; > +} This got worse because it's *named* like a boolean, but the return value can't be used like a boolean, which makes callers really hard to read, e.g., this: if (p2sb_valid_resource(res)) /* do something */ does exactly the opposite of what the reader expects. I see that you want to use this -ENOENT return value in the callers: > +static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) > +{ > + ... > + return p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)].res); > +} > + * 0 on success or appropriate errno value on error. > + */ > +int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem) > +{ > + ... > + ret = p2sb_valid_resource(&cache->res); > + if (ret) > + return ret; But I think these would be much clearer as something like this: static bool p2sb_valid_resource(struct resource *res) { if (res->flags) return true; return false; } static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) { ... if (!p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)].res)) return -ENOENT; return 0; } Bjorn