Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp539631imm; Wed, 17 Oct 2018 04:32:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Q6xG7mpgDH6054WyjCTc9jevwhBT+3T90+/tD2GsHCHdyi3zYIcVeQChXpaigOCaXx4mX X-Received: by 2002:a62:fd0b:: with SMTP id p11-v6mr25698412pfh.167.1539775963443; Wed, 17 Oct 2018 04:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539775963; cv=none; d=google.com; s=arc-20160816; b=SMXdETQMksT1N/L4enDxd1CZA7ZgN8kiB5sA7sDzqH+dv9WyfRr3Sk+NVRYCtDkudB 32Aa9Eujl+9ZaHz0NzKCVlDsFNIwDW7X7Ij9KntT+tqm9PyZAJ0gZ7sUZbt0+YWnHkqy zPyPSoyBWJvG1z5A6/BNJ0IliCIbKSDCnN24tdY/7Q9dBxj7ut5JIeMYX6e7vwCsgVY6 iUlqWBXjAAvRJ5evvKzc/ayqjwt/BalFlVCIo5+lsY0cfuosipjrJrzYQKMC9KWIPFaN JRYVBF67LZwxMWKa4GE+y0EyW+oXiCvUkyiuNw5ibc0zzv46mr1xe/QCKhqmlSmazgWH dQCw== 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=Gm14wcv0UJ3h+HAjuqDJB23Iqp24MW+nuJIjnVCbduQ=; b=RQ9JHa0m22K/AbZPK6K9uEf8YclhGqwKrY8b57s+3/ORkPRo+ctT4lGcvFzFp6qNJ/ O5mVzHrrJBfGpLCTjrF8EYivm4QWkJD8F+nUu8rLPQCYJaYy8nooT8LjQCjWY5Phx8Ll dEFY3gPUNXpuEor55i+wTU7q5ipRLTv+WVkqoX7+oF+UkfC0rfZoydu0y6hRZO6Hp6D5 qc354i1aAf8X2DOzNWrf2K/+UmrDbtSdt3vnNmWajBFX3CedX/5qGXPAn7pj20vw4QCQ ZhywJzJp4jHOb5oXN8VYPeGXugeSFCZrZZcd1u+gjKnWmRgy+e84D9Fpj8Pzg+M5nwTo LbaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J4wQBUOa; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q143-v6si16235527pgq.483.2018.10.17.04.32.27; Wed, 17 Oct 2018 04:32:43 -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=@gmail.com header.s=20161025 header.b=J4wQBUOa; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbeJQTZn (ORCPT + 99 others); Wed, 17 Oct 2018 15:25:43 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:46186 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbeJQTZn (ORCPT ); Wed, 17 Oct 2018 15:25:43 -0400 Received: by mail-qk1-f193.google.com with SMTP id q12-v6so16162307qkl.13 for ; Wed, 17 Oct 2018 04:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Gm14wcv0UJ3h+HAjuqDJB23Iqp24MW+nuJIjnVCbduQ=; b=J4wQBUOa6lAcuFkWggJY9RyE9k9J4wWwkgisTHLo3u0Ta3naw17TU9/BPNbI4TMoZl IhR2d5r58fdDgf9I4t/qKGVkkHQXtYxATLtyIaBow17MUoquaeM/vuvEsa/vVCF51K8d XGh8w6AQoRnk33AwmnPjUVZROsFstNsXBJ8WvWbiULNJvpjJwqG/Eqg3qhWSDxIN3Ti2 WSM64PLXaE7inckmajwlmqyHNKhOc//pJKd/rmZH9pr3+JcYZfKEIiRiQyjgJzhHcacH 9dIpHHThvMvgQ0wpMheDKVUZI5Hfx+XJHv9Ye49sIm5WiiGezu5T7XOchkr2Dn9P9BI+ 4pwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Gm14wcv0UJ3h+HAjuqDJB23Iqp24MW+nuJIjnVCbduQ=; b=WB5pYfe2/TnvB4tvkfEWfyR6Yjj2mqvNFbL9HTvE5acsAvXseglXQWy67IpCD52ima PG5BMeZdcul0XFn+D+c/SoylU22o6/k4y64ndYQ3ZwMDyzIdItJhQA0IXrDeb0wATWRz f/S+sUcwZ4b6OY0cMMU5aKdqSUENcVJyHsgwpms3dF/ccIl3IR9M1+3KPUy+qfltgku0 UX48FwzdgPT4v39Kb1pVGPbf1zokh/7HIKFEX53s1B63O1CO9rF5LyAxzaqooP4Pesbs 3JGygBm4LYN5OCYLHy3ff59ltuTfmqaYTX6eMKgkaNMqlCvIGkM1dn1pAyN08wxtSU1W WIDA== X-Gm-Message-State: ABuFfohKYlyntrtsEjWCSAcNdEJhNUhGD1k0CCCR3R+woo3ccls+aiGs 8bQZRzXsjgaDQvfV97YvbINfIKrjp4I6WybylYM= X-Received: by 2002:a37:7983:: with SMTP id u125-v6mr22780311qkc.219.1539775826426; Wed, 17 Oct 2018 04:30:26 -0700 (PDT) MIME-Version: 1.0 References: <20181017085824.30806-1-a.hajda@samsung.com> In-Reply-To: <20181017085824.30806-1-a.hajda@samsung.com> From: Andy Shevchenko Date: Wed, 17 Oct 2018 14:30:15 +0300 Message-ID: Subject: Re: [PATCH v2 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 Mailing List , Mark Brown 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 Wed, Oct 17, 2018 at 11:58 AM 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 > Looks good to me, Reviewed-by: Andy Shevchenko > --- > 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, ...); > + > /* Create alias, so I can be autoloaded. */ > #define MODULE_ALIAS_CHARDEV(major,minor) \ > MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor)) > -- > 2.18.0 > -- With Best Regards, Andy Shevchenko