Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S944749AbcJaQv3 (ORCPT ); Mon, 31 Oct 2016 12:51:29 -0400 Received: from mx2.suse.de ([195.135.220.15]:52507 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S944441AbcJaQsp (ORCPT ); Mon, 31 Oct 2016 12:48:45 -0400 From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xen.org Cc: david.vrabel@citrix.com, boris.ostrovsky@oracle.com, Juergen Gross Subject: [PATCH 01/12] xen: introduce xenbus_read_unsigned() Date: Mon, 31 Oct 2016 17:48:19 +0100 Message-Id: <1477932510-28594-2-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.6 In-Reply-To: <1477932510-28594-1-git-send-email-jgross@suse.com> References: <1477932510-28594-1-git-send-email-jgross@suse.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1728 Lines: 53 There are multiple instances of code reading an optional unsigned parameter from Xenstore via xenbus_scanf(). Instead of repeating the same code over and over add a service function doing the job. Signed-off-by: Juergen Gross --- drivers/xen/xenbus/xenbus_xs.c | 15 +++++++++++++++ include/xen/xenbus.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index 22f7cd7..99dfdfa 100644 --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c @@ -559,6 +559,21 @@ int xenbus_scanf(struct xenbus_transaction t, } EXPORT_SYMBOL_GPL(xenbus_scanf); +/* Read an (optional) unsigned value. */ +unsigned int xenbus_read_unsigned(const char *dir, const char *node, + unsigned int default_val) +{ + unsigned int val; + int ret; + + ret = xenbus_scanf(XBT_NIL, dir, node, "%u", &val); + if (ret <= 0) + val = default_val; + + return val; +} +EXPORT_SYMBOL_GPL(xenbus_read_unsigned); + /* Single printf and write: returns -errno or 0. */ int xenbus_printf(struct xenbus_transaction t, const char *dir, const char *node, const char *fmt, ...) diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h index 32b944b..271ba62 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -151,6 +151,10 @@ __scanf(4, 5) int xenbus_scanf(struct xenbus_transaction t, const char *dir, const char *node, const char *fmt, ...); +/* Read an (optional) unsigned value. */ +unsigned int xenbus_read_unsigned(const char *dir, const char *node, + unsigned int default_val); + /* Single printf and write: returns -errno or 0. */ __printf(4, 5) int xenbus_printf(struct xenbus_transaction t, -- 2.6.6