Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp627675ybt; Wed, 24 Jun 2020 07:28:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywZWM04xBYTW7iva0X0uwt/ECycRj+hMAsjg6cWR1okpyYHv0gFdZsAmuzT8Yq4F73TKYP X-Received: by 2002:a05:6402:3044:: with SMTP id bu4mr27163507edb.69.1593008907680; Wed, 24 Jun 2020 07:28:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593008907; cv=none; d=google.com; s=arc-20160816; b=c0zW6q2kbLnkiXpUh10CRJWs4fHBiWcSbKwuU7lAV6ypUqv/CaaEzVXTV+QtGDjEsG Au5W3HtU84BENU3jZJtZmC6WrP3kDUO+X7+qYImwZB3fIQ32iV+kV24AV6Q4c50YToqD SdOGEoxabuBjVz1D4R2MNfJ/CtwrLkawDrQlDcPHt4+OfXOyqJmR2mpQ9oYgOdfInfaE cBFwfDEIL0WotgPPuBgDHuyHvkY2hjU7rg5O20VCCTE8gmUDPRtrb+WXTfzYy5WaurSd ah1OzYtybmySrsRN3w91nmgHMxqM3Bx3Wcg3qUXtg/HnMY+kEYRsCQVQgje68goK6kyx xiew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=7ySXhg90SWF99dhvdBw/2m0kUt2GI7w4WGuNzDbGjhc=; b=Ca9cYI3nt3Qe5uJsvcAu7rGily/7V1dpw91MBzCLUwK1Yn+yQJwXTRP0+3ZPhMp7ny 4797jRKU7Y7Pu9jWyjm0L/lM/yBDd0vBRF2f0bpOrHmmU1wtDgmVUD81j5zsDFn5XoGh qpvYla9JyCb/pbxSY7Qb8al3EbVIWTKz2i4IJEgfz/w4EInXZj0cbZGX7AXpcHv+uh75 U3IGfMq6KOKUw6oPp+/X1f4JyS60vSZYqq4LZLQ0ap70eZgFG1yjaYUIox+kBE+5XNIq fGUzyQbJy3UGMMA7xusK24VczNbZWJbo0kY0jU0zACT2o9k4/E+rNJhgkCWcTcBOuLrW cKxg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o5si3291476edj.37.2020.06.24.07.28.00; Wed, 24 Jun 2020 07:28:27 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390393AbgFXOZi (ORCPT + 99 others); Wed, 24 Jun 2020 10:25:38 -0400 Received: from foss.arm.com ([217.140.110.172]:55658 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388115AbgFXOZh (ORCPT ); Wed, 24 Jun 2020 10:25:37 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 18AE11FB; Wed, 24 Jun 2020 07:25:37 -0700 (PDT) Received: from [10.57.9.128] (unknown [10.57.9.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BE6E53F6CF; Wed, 24 Jun 2020 07:25:34 -0700 (PDT) Subject: Re: [RESEND PATCH v5 3/5] drivers core: allow probe_err accept integer and pointer types To: Andy Shevchenko Cc: Andrzej Hajda , Greg Kroah-Hartman , Jernej Skrabec , "Rafael J. Wysocki" , Jonas Karlman , Bartlomiej Zolnierkiewicz , Linux Kernel Mailing List , "open list:DRM DRIVERS" , Russell King - ARM Linux , Neil Armstrong , Mark Brown , Laurent Pinchart , Daniel Vetter , linux-arm Mailing List , Marek Szyprowski References: <20200624114127.3016-1-a.hajda@samsung.com> <20200624114127.3016-4-a.hajda@samsung.com> <2203e0c2-016b-4dbe-452d-63c857f06dd1@arm.com> From: Robin Murphy Message-ID: Date: Wed, 24 Jun 2020 15:25:33 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-24 13:55, Andy Shevchenko wrote: > On Wed, Jun 24, 2020 at 3:37 PM Robin Murphy wrote: >> On 2020-06-24 12:41, Andrzej Hajda wrote: >>> Many resource acquisition functions return error value encapsulated in >>> pointer instead of integer value. To simplify coding we can use macro >>> which will accept both types of error. >>> With this patch user can use: >>> probe_err(dev, ptr, ...) >>> instead of: >>> probe_err(dev, PTR_ERR(ptr), ...) >>> Without loosing old functionality: >>> probe_err(dev, err, ...) >> >> Personally I'm not convinced that simplification has much value, and I'd >> say it *does* have a significant downside. This: >> >> if (IS_ERR(x)) >> do_something_with(PTR_ERR(x)); >> >> is a familiar and expected pattern when reading/reviewing code, and at a >> glance is almost certainly doing the right thing. If I see this, on the >> other hand: >> >> if (IS_ERR(x)) >> do_something_with(x); > > I don't consider your arguments strong enough. You are appealing to > one pattern vs. new coming *pattern* just with a different name and > actually much less characters to parse. We have a lot of clean ups > like this, have you protested against them? JFYI: they are now > *established patterns* and saved a ton of LOCs in some of which even > were typos. I'm not against probe_err() itself, I think that stands to be a wonderfully helpful thing that will eliminate a hell of a lot of ugly mess from drivers. It's only the specific elision of 9 characters worth of "PTR_ERR()" in certain cases that I'm questioning. I mean, we've already got +20 characters leeway now that checkpatch has acknowledged all that blank space on the right-hand side of all my editor windows. Sure, there's not necessarily anything bad about introducing a new pattern in itself, but it's not going to *replace* the existing pattern of "IS_ERR() pairs with PTR_ERR()", because IS_ERR() is used for more than driver probe error handling. Instead, everybody now has to bear in mind that the new pattern is "IS_ERR() pairs with PTR_ERR(), except sometimes when it doesn't - last time I looked only probe_err() was special, but maybe something's changed, I'll have to go check...", and that's just adding cognitive load for the sake of not even saving a linewrap any more. First, the wave of Sparse errors from the build bots hits because it turns out casting arbitrary pointers appropriately is hard. As it washes past, the reality of authors' and maintainers' personal preferences comes to bear... some inevitably prefer to keep spelling out PTR_ERR() in probe_err() calls for the sake of clarity, bikeshedding ensues, and the checkpatch and Coccinelle armies mobilise to send unwanted patches changing things back and forth. Eventually, in all the confusion, a synapse misfires in a muddled developer's mind, an ERR_PTR value passed to kfree() "because kfree() is robust" slips through, and a bug is born. And there's the thing: inconsistency breeds bugs. Sometimes, of course, there are really good reasons to be inconsistent. Is 9 characters per line for a few hundred lines across the kernel tree really a really good reason? The tersest code is not always the most maintainable. Consider that we could also save many more "tons of LoC" by rewriting an entire category of small if/else statements with ternaries. Would the overall effect on maintainability be positive? I don't think so. And yeah, anyone who pipes up suggesting that places where an ERR_PTR value could be passed to probe_err() could simply refactor IS_ERR() checks with more uses of the god-awful PTR_ERR_OR_ZERO() obfuscator gets a long stare of disapproval... Robin. >> my immediate instinct is to be suspicious, and now I've got to go off >> and double-check that if do_something_with() really expects a pointer >> it's also robust against PTR_ERR values. Off-hand I can't think of any >> APIs that work that way in the areas with which I'm familiar, so it >> would be a pretty unusual and non-obvious thing. >