Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2525662imu; Sun, 23 Dec 2018 01:37:01 -0800 (PST) X-Google-Smtp-Source: ALg8bN5CmANN1oBph0Q2a5mQOOL5udMki6mB1mgmzR65MFqDsOd1DNmxjM1Rdt36ST1ayO0wIGiU X-Received: by 2002:a63:4456:: with SMTP id t22mr8837692pgk.0.1545557821785; Sun, 23 Dec 2018 01:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545557821; cv=none; d=google.com; s=arc-20160816; b=BiuRidD2kCWCTC/TCeZoFdahN7Y7DZ2DVTQlPOs6eie3xapIiApZ8a2DZ4emKLF3/J jlTai4uZloMa+CGw0n12JSRd1+rOYtJ1frq5ycoS5ciB3VMvAv8G1jDIi6YDcq4zFaq8 aTAPgiTAF+Z+JCuLCzzGBpKc7NNhnRRtEKYVS7Nq+RjuGTsvQjSe5JIUJgDOnsVDTexN fxYUccmkmT6re3ZmvzJN/gCzifjRImsm1OqfSZNdMhwyY66dpkzL1m3mIXqoqTvKiNPt Vy+fL2Og5g4fWJ6lEe3XwhJwrDOkp4In1m/dwnfIsh9Vw+uIEBrWWXLxq4bQo907iUpP gKIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=JaEwMLY1q6hCoBcfvmKIk6loxdj9awvQkcpbfyCiFZo=; b=kwg6NuQ0r5MDbxHsdPdoxKueY8JlcunoUwI87QB1pzJMSAISaSSDMTsuf51NqQWjL0 E8zr8hjYTqxEjhDi/lXan74tZLdSm3qZJcxOLVspoqMM286P/nG8Txw7sJlfA4P4KlnF Kx/RTgXVKWi/bbpFRdpO69UB2wWD1V/o484cHRDO5BzFfQAlwQfscbKqrlsONuKHYh7N lyPPiYwwuELrXdlSr0VckUdZlIMfT3mDFndyL1szFWiFVZa8ulOYfzbm/+w/AzkPRuIm 3SEAxyYTLcBwfbBGWllIr0Mqct3/V81BNGS8W24d6KakQROSMi11vhPq111rQcBIAzur Wp+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=btkXoLL6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15si24913651pgm.420.2018.12.23.01.36.46; Sun, 23 Dec 2018 01:37:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=btkXoLL6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731199AbeLUWr7 (ORCPT + 99 others); Fri, 21 Dec 2018 17:47:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:41422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbeLUWr7 (ORCPT ); Fri, 21 Dec 2018 17:47:59 -0500 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A8D8B21970 for ; Fri, 21 Dec 2018 22:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545432477; bh=oRyKYDLBkCt8PohvGhKj7Ezcv2YNCnLOR+AO7rpNPHg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=btkXoLL614+KGQguZ9tGRiIzzCdv5LOYKHUu4SgVXHG+YnmZk9apf61aPMRv5SK53 HuyTKFo4/XSl+8hf5fyXSmzeSIp1ecQksBGrX9nlwOycMqrP8hLJ5cjXFao7grDkb1 3oyIjilc/NGhglzv6FXp/u4ugy9MZQhFU8uE1Nws= Received: by mail-wr1-f46.google.com with SMTP id q18so6748744wrx.9 for ; Fri, 21 Dec 2018 14:47:57 -0800 (PST) X-Gm-Message-State: AJcUukcQLm47/4SLaGXv+T/sAIdypL5aWuTKblYdWE4+rzY265OBAyVK xJlmP7nFDlh/9PC7mSo0+iBl0kTmUFOjh2UVw9NaYg== X-Received: by 2002:adf:cd0e:: with SMTP id w14mr4463016wrm.218.1545432476043; Fri, 21 Dec 2018 14:47:56 -0800 (PST) MIME-Version: 1.0 References: <20181220102247.4911-1-a.hajda@samsung.com> <20181220102247.4911-2-a.hajda@samsung.com> <20181220111403.GB10978@kroah.com> In-Reply-To: From: Rob Herring Date: Fri, 21 Dec 2018 16:47:44 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 1/3] driver core: add probe_err log helper To: Andrzej Hajda Cc: Greg Kroah-Hartman , Bartlomiej Zolnierkiewicz , Marek Szyprowski , "Rafael J. Wysocki" , Linux Kernel Mailing List , Javier Martinez Canillas , linux-arm-kernel , Andy Shevchenko , Mark Brown , Russell King - ARM Linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 20, 2018 at 5:38 AM Andrzej Hajda wrote: > > On 20.12.2018 12:14, Greg Kroah-Hartman wrote: > > On Thu, Dec 20, 2018 at 11:22:45AM +0100, Andrzej Hajda wrote: > >> During probe every time driver gets resource it should usually check for error > >> printk some message if it is not -EPROBE_DEFER and return the error. This > >> pattern is simple but requires adding few lines after any resource acquisition > >> code, as a result it is often omited or implemented only partially. > >> probe_err helps to replace such code sequences with simple call, so code: > >> if (err != -EPROBE_DEFER) > >> dev_err(dev, ...); > >> return err; > >> becomes: > >> return probe_err(dev, err, ...); > > Can you show a driver being converted to use this to show if it really > > will save a bunch of lines and make things simpler? Usually you are > > requesting lots of resources so you need to do more than just return, > > you need to clean stuff up first. > > > I have posted sample conversion patch (generated by cocci) in previous > version of this patchset [1]. > > I did not re-posted it again as it is quite big patch and it will not be > applied without prior splitting it per subsystem. > > Regarding stuff cleaning: devm_* usually makes it unnecessary, but also > even with necessary cleaning you can profit from probe_err, you just > calls it without leaving probe - you have still handled correctly probe > deferring. > > Here is sample usage (taken from beginning of the mentioned patch): > > --- > diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c > index 4b900fc659f7..52e891fe1586 100644 > --- a/drivers/ata/libahci_platform.c > +++ b/drivers/ata/libahci_platform.c > @@ -581,11 +581,8 @@ int ahci_platform_init_host(struct platform_device *pdev, > int i, irq, n_ports, rc; > > irq = platform_get_irq(pdev, 0); > - if (irq <= 0) { > - if (irq != -EPROBE_DEFER) > - dev_err(dev, "no irq\n"); > - return irq; > - } > + if (irq <= 0) > + return probe_err(dev, irq, "no irq\n"); Shouldn't platform_get_irq (or what it calls) print the error message (like we do for kmalloc), rather than every driver? We could get rid of lots of error strings that way. I guess there are cases where no irq is not an error and we wouldn't want to always print an error. In some cases like that, we have 2 versions of the function. Not what you're addressing here exactly, but what I'd like to see is the ability to print the exact locations generating errors in the first place. That would require wrapping all the error code assignments and returns (or at least the common sources). If we're going to make tree wide changes, then that might be the better place to put the effort. If we had that, then maybe we'd need a lot fewer error messages in drivers. I did a prototype implementation and coccinelle script a while back that I could dust off if there's interest. It was helpful in finding the source of errors, but did have some false positives printed. Rob