Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp556212imm; Wed, 17 Oct 2018 04:49:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV628huiH1q4/iku+omL9S80FIYvIkODh/1+ZnPRQ+t6ZJspyVw+ouBZY7ngATdUb8PImJUQw X-Received: by 2002:a63:fe13:: with SMTP id p19-v6mr23843484pgh.265.1539776989016; Wed, 17 Oct 2018 04:49:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539776988; cv=none; d=google.com; s=arc-20160816; b=SaAv9gIRc4jZerK4K5rmpAutdRaXzNapJBN8Se4mB9vUnuB2U05MJHHZ+HlemtgTL4 eDzNeaUmfFt9hfL7rRdYs7y+GuVL/xEOWtrzebiXPRva2VE72EXsc2qpOtTJwuh7AH10 HIodaS7Y7BCRXCLRkqxPZf2+OL62HiN7bM/mIlsJaTOVxg8OvR2zLKKEwzVfz/f+6ZdS rnXBL0Z/46dWq7+f6zliEVbDO66UMvmLzQHYAR1dFYivPqKJy+jKo809peD7PLyzpG9r VTwBKEQkkdNFJaTfZcBpIL0LVMHrZz5bFqz6baP6FQ/UxYtroBdCRi1DEEtT+J6//6mD fHvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=RttqJQReAPMRdKz96uwKrs52bUTvRKR04FGmAkGJ/lQ=; b=pZZx8WRaZHNHVA/CaVyEZd+fisvPD2z83gwijjWkCV+5hI8aYdWBviEGqgRWB6wtgW 5zl9kCs7gK1EhcAdObBVK+sQKUC4hMN6Qla4tI0GjHGpSQ7Hq8dXhDQTGkJ/WfheH39u hBOj0QeY1Rdh4d+MG4gl9BFWxubJEE6KpwXKDrnoMdNGagrM/9eBrb9NB+DiGw9SQdXx nZlMT88I8pD4hm99GIXWshw+w5LORwM+JfsGWJJYBwdjH2AbsK2Pf1rc4LL+QgQAowri oB9z7XdhaGrkXoIJmmRl3IM0EjIphCHCa0rCt/HEml2+A/SMES4+2ZzVpnpLwx4uDKe1 XoEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vB4zQPzb; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 6-v6si16744277pgt.320.2018.10.17.04.49.32; Wed, 17 Oct 2018 04:49:48 -0700 (PDT) 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=vB4zQPzb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727097AbeJQTob (ORCPT + 99 others); Wed, 17 Oct 2018 15:44:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:34850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726954AbeJQToa (ORCPT ); Wed, 17 Oct 2018 15:44:30 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 40BC92098A; Wed, 17 Oct 2018 11:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539776949; bh=LFzkml6stIefEjZMuWrkiYvJoeSOY3JSdRj37HdcbLQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vB4zQPzb59RP6wlFIWTgnJExPyfuCopHIi0SrE8c0cPNuF79rUY/qMYZDiQdz9McK bx5kjjO/aw6usPOsmRcE1d8qB2fI06t97E5gwy+0e+AP03HFYASRMVsraIpyve75xg lTr4AHEfE3niKPiBp1GtLKo8FOcSuUq2an3eEyYY= Date: Wed, 17 Oct 2018 13:49:06 +0200 From: Greg Kroah-Hartman To: Andrzej Hajda Cc: Bartlomiej Zolnierkiewicz , Marek Szyprowski , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Javier Martinez Canillas , linux-arm-kernel@lists.infradead.org, andy.shevchenko@gmail.com, Mark Brown Subject: Re: [PATCH v2 1/3] driver core: add probe_err log helper Message-ID: <20181017114906.GA32302@kroah.com> References: <20181017085824.30806-1-a.hajda@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181017085824.30806-1-a.hajda@samsung.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 17, 2018 at 10:58:24AM +0200, 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, ...); > > Signed-off-by: Andrzej Hajda > Reviewed-by: Javier Martinez Canillas > > --- > v2: > - added error value to log message, > - fixed code style, > - added EXPORT_SYMBOL_GPL, > - Added R-B by Javier (I hope the changes did not invalidate it). > --- > drivers/base/core.c | 37 +++++++++++++++++++++++++++++++++++++ > include/linux/device.h | 2 ++ > 2 files changed, 39 insertions(+) > > diff --git a/drivers/base/core.c b/drivers/base/core.c > index 04bbcd779e11..aa6f3229d066 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -3067,6 +3067,43 @@ define_dev_printk_level(_dev_info, KERN_INFO); > > #endif > > +/** > + * probe_err - probe error check and log helper > + * @dev: the pointer to the struct device > + * @err: error value to test > + * @fmt: printf-style format string, not ended with newline > + * @...: arguments as specified in the format string > + * > + * This helper implements common pattern present in probe functions for error > + * checking: print message if the error is not -EPROBE_DEFER and propagate it. > + * It replaces code sequence: > + * if (err != -EPROBE_DEFER) > + * dev_err(dev, ...); > + * return err; > + * with > + * return probe_err(dev, err, ...); > + * > + * Returns @err. > + * > + */ > +int probe_err(const struct device *dev, int err, const char *fmt, ...) > +{ > + struct va_format vaf; > + va_list args; > + > + if (err == -EPROBE_DEFER) > + return err; > + > + va_start(args, fmt); > + vaf.fmt = fmt; > + vaf.va = &args; > + dev_err(dev, "%pV, %d\n", &vaf, err); > + va_end(args); > + > + return err; > +} > +EXPORT_SYMBOL_GPL(probe_err); > + > static inline bool fwnode_is_primary(struct fwnode_handle *fwnode) > { > return fwnode && !IS_ERR(fwnode->secondary); > diff --git a/include/linux/device.h b/include/linux/device.h > index 90224e75ade4..06c2c797d132 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -1577,6 +1577,8 @@ do { \ > WARN_ONCE(condition, "%s %s: " format, \ > dev_driver_string(dev), dev_name(dev), ## arg) > > +int probe_err(const struct device *dev, int err, const char *fmt, ...); __printf(3, 4) ?