From patchwork Mon Jan 16 20:41:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 91578 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp190508qgi; Mon, 16 Jan 2017 12:41:56 -0800 (PST) X-Received: by 10.98.103.20 with SMTP id b20mr39728609pfc.166.1484599316104; Mon, 16 Jan 2017 12:41:56 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 59si22580206plp.314.2017.01.16.12.41.55; Mon, 16 Jan 2017 12:41:56 -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; 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 S1751378AbdAPUlj (ORCPT + 25 others); Mon, 16 Jan 2017 15:41:39 -0500 Received: from mail-oi0-f66.google.com ([209.85.218.66]:35665 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751026AbdAPUlZ (ORCPT ); Mon, 16 Jan 2017 15:41:25 -0500 Received: by mail-oi0-f66.google.com with SMTP id x84so13467507oix.2; Mon, 16 Jan 2017 12:41:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bPYF7caYD8oezYfPsNNtzli770eajDsXGrl+l1oQ8rM=; b=QtX9i+D/Cpa8N3+ZDwM/sghspdse/vRCy3yBzHQdgSzJCG5Owsv8/6/Wlm8QRHjXjC +lFNhYtd42Sf1I63GI1J7f9bgffo7qixWstYGHG+ERKNiOOtIhZ4Q5HIxrJqBCArlv0b grQgX2giGiZVQBTwEb8NGN3a5+5S+9QgnNVMRCIG76B1NwNaLLGVsvWYQaqMKsb8l7Lp 1qyOdRnj1BXEcRGnb0aRjzRb2L7mZghE1vvddWnUFsK0qQNur0v0gQgo9ZmGV9pBthOf Hr86qTsNH5529iaDvYwTFWuUr+VRIGPDZJ0GirX5jG0GNfSqFgv1/MAZVmhMp/VO0xtD Ro/A== X-Gm-Message-State: AIkVDXJh6mWdrLal96n2YOoOIZ8u0hsFGDPNEK9oejvwDG0sIOaDDpwC7z7njYgEHsS/3g== X-Received: by 10.202.222.11 with SMTP id v11mr17841541oig.194.1484599284973; Mon, 16 Jan 2017 12:41:24 -0800 (PST) Received: from rob-hp-laptop.herring.priv (72-48-98-129.dyn.grandenetworks.net. [72.48.98.129]) by smtp.googlemail.com with ESMTPSA id v14sm1686881otv.0.2017.01.16.12.41.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jan 2017 12:41:24 -0800 (PST) From: Rob Herring To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Frank Rowand Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Greg Kroah-Hartman , linuxppc-dev@lists.ozlabs.org Subject: [PATCH 2/2] of: Add function for generating a DT modalias with a newline Date: Mon, 16 Jan 2017 14:41:22 -0600 Message-Id: <20170116204122.5858-2-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170116204122.5858-1-robh@kernel.org> References: <20170116204122.5858-1-robh@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The modalias sysfs attr is lacking a newline for DT aliases on platform devices. The macio and ibmebus correctly add the newline, but open code it. Introduce a new function, of_device_modalias(), that fills the buffer with the modalias including the newline and update users of the old of_device_get_modalias function. Signed-off-by: Rob Herring Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: Greg Kroah-Hartman Cc: Frank Rowand Cc: linuxppc-dev@lists.ozlabs.org --- arch/powerpc/platforms/pseries/ibmebus.c | 5 +---- drivers/base/platform.c | 2 +- drivers/macintosh/macio_sysfs.c | 7 +------ drivers/of/device.c | 16 +++++++++++++++- include/linux/of_device.h | 7 +++---- 5 files changed, 21 insertions(+), 16 deletions(-) -- 2.10.1 diff --git a/arch/powerpc/platforms/pseries/ibmebus.c b/arch/powerpc/platforms/pseries/ibmebus.c index 614c28537141..18f5a7a2896f 100644 --- a/arch/powerpc/platforms/pseries/ibmebus.c +++ b/arch/powerpc/platforms/pseries/ibmebus.c @@ -410,10 +410,7 @@ static ssize_t name_show(struct device *dev, static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) { - ssize_t len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2); - buf[len] = '\n'; - buf[len+1] = 0; - return len+1; + return of_device_modalias(dev, buf, PAGE_SIZE); } static struct device_attribute ibmebus_bus_device_attrs[] = { diff --git a/drivers/base/platform.c b/drivers/base/platform.c index c4af00385502..d92f60d7f15d 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -837,7 +837,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a, struct platform_device *pdev = to_platform_device(dev); int len; - len = of_device_get_modalias(dev, buf, PAGE_SIZE -1); + len = of_device_modalias(dev, buf, PAGE_SIZE); if (len != -ENODEV) return len; diff --git a/drivers/macintosh/macio_sysfs.c b/drivers/macintosh/macio_sysfs.c index 8eb40afbd0f5..0b1f9c76c68d 100644 --- a/drivers/macintosh/macio_sysfs.c +++ b/drivers/macintosh/macio_sysfs.c @@ -41,12 +41,7 @@ compatible_show (struct device *dev, struct device_attribute *attr, char *buf) static ssize_t modalias_show (struct device *dev, struct device_attribute *attr, char *buf) { - int len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2); - - buf[len] = '\n'; - buf[len+1] = 0; - - return len+1; + return of_device_modalias(dev, buf, PAGE_SIZE); } static ssize_t devspec_show(struct device *dev, diff --git a/drivers/of/device.c b/drivers/of/device.c index bd620452f255..f3c3108d5a3a 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -176,7 +176,7 @@ const void *of_device_get_match_data(const struct device *dev) } EXPORT_SYMBOL(of_device_get_match_data); -ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) +static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) { const char *compat; int cplen, i; @@ -227,6 +227,20 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) } /** + * of_device_modalias - Fill buffer with newline terminated modalias string + */ +ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len) +{ + ssize_t sl = of_device_get_modalias(dev, str, len - 2); + if (sl < 0) + return sl; + + str[sl++] = '\n'; + str[sl] = 0; + return sl; +} + +/** * of_device_uevent - Display OF related uevent information */ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) diff --git a/include/linux/of_device.h b/include/linux/of_device.h index cc7dd687a89d..971d7250a8a4 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -35,8 +35,7 @@ extern void of_device_unregister(struct platform_device *ofdev); extern const void *of_device_get_match_data(const struct device *dev); -extern ssize_t of_device_get_modalias(struct device *dev, - char *str, ssize_t len); +extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len); extern void of_device_uevent(struct device *dev, struct kobj_uevent_env *env); extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env); @@ -72,8 +71,8 @@ static inline const void *of_device_get_match_data(const struct device *dev) return NULL; } -static inline int of_device_get_modalias(struct device *dev, - char *str, ssize_t len) +static inline int of_device_modalias(struct device *dev, + char *str, ssize_t len) { return -ENODEV; }