From patchwork Fri Jun 10 12:02:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 581240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC82EC433EF for ; Fri, 10 Jun 2022 12:02:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346723AbiFJMCV (ORCPT ); Fri, 10 Jun 2022 08:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346799AbiFJMCV (ORCPT ); Fri, 10 Jun 2022 08:02:21 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16A3A3E0EA; Fri, 10 Jun 2022 05:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654862540; x=1686398540; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=cAnK+F86CV/moe3BVaa7l+Gx92UVQLrvBwjZH561G94=; b=W+uI3vh7CjD+Pg172FaBvAi3Omeg5peDjhpwJNKFRLSoEDWAI04QERqi 4jIPTeL0L+BHG0KI0D3E6kOk18aA7LE8pHVssjiLJ0h8LpvHOXYZdunZr 8Fc5DzPRLRNIkCjIOvYXPTegQE9sU+7W/v/gFk1BqUrE2pUQFLcfdkji+ X+NSqh4RBkIYrcZikBQ2JTbBkQiddMgeo2EXG2XfLozDg1f5F2ykgvdaZ n7nFjJ1WFFjfxF7SVc1XzEI38FEeFcbMdddchI4rMRSmCbddamvPllFCZ cEgLGcFz+oMqTVVTLbTNQ4HHJO/tJjKdZFxR06EzSVuZU+0MGI6dPW9vn A==; X-IronPort-AV: E=McAfee;i="6400,9594,10373"; a="266376380" X-IronPort-AV: E=Sophos;i="5.91,290,1647327600"; d="scan'208";a="266376380" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 05:02:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,290,1647327600"; d="scan'208";a="684508487" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 10 Jun 2022 05:02:17 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 01FDD18F; Fri, 10 Jun 2022 15:02:20 +0300 (EEST) From: Andy Shevchenko To: Greg Kroah-Hartman , Mark Brown , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Cc: "Rafael J. Wysocki" , Andy Shevchenko Subject: [PATCH v2 1/2] driver core: Introduce device_find_any_child() helper Date: Fri, 10 Jun 2022 15:02:18 +0300 Message-Id: <20220610120219.18988-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org There are several places in the kernel where this kind of functionality is being used. Provide a generic helper for such cases. Signed-off-by: Andy Shevchenko --- v2: renamed method (Greg), refactored it (Rafael) drivers/base/core.c | 20 ++++++++++++++++++++ include/linux/device.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 7cd789c4985d..a519307fda60 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3832,6 +3832,26 @@ struct device *device_find_child_by_name(struct device *parent, } EXPORT_SYMBOL_GPL(device_find_child_by_name); +static int match_any(struct device *dev, void *unused) +{ + return 1; +} + +/** + * device_find_any_child - device iterator for locating a child device, if any. + * @parent: parent struct device + * + * This is similar to the device_find_child() function above, but it + * returns a reference to a child device, if any. + * + * NOTE: you will need to drop the reference with put_device() after use. + */ +struct device *device_find_any_child(struct device *parent) +{ + return device_find_child(parent, NULL, match_any); +} +EXPORT_SYMBOL_GPL(device_find_any_child); + int __init devices_init(void) { devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL); diff --git a/include/linux/device.h b/include/linux/device.h index dc941997795c..424b55df0272 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -905,6 +905,8 @@ struct device *device_find_child(struct device *dev, void *data, int (*match)(struct device *dev, void *data)); struct device *device_find_child_by_name(struct device *parent, const char *name); +struct device *device_find_any_child(struct device *parent); + int device_rename(struct device *dev, const char *new_name); int device_move(struct device *dev, struct device *new_parent, enum dpm_order dpm_order); From patchwork Fri Jun 10 12:02:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 581093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D5B5C433EF for ; Fri, 10 Jun 2022 12:02:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347511AbiFJMCY (ORCPT ); Fri, 10 Jun 2022 08:02:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347368AbiFJMCW (ORCPT ); Fri, 10 Jun 2022 08:02:22 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCE433E5C3; Fri, 10 Jun 2022 05:02:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654862541; x=1686398541; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fUe1OfJHggHu1g9C1q0AXthmCAvU/GJYCK0MIj3eotA=; b=eKhyQ9eX4yWT98PEUBrCDKrenfoR6RXfvGPnp5dP2QWwJHm4WR8VUjU6 c4GVO7i6KtUb8GPGk91fp70ULjLS0mtv7IJt9GDaRA11NK9+g3ViaKz2R /w2DCyoCM60yH9sMSyFkJoUIfO4I5Bep/JsjoqLPM2ypFQEbpPo7SKO+p BOavdVKnfgHV7boGYxCRy53Ncj4WbVuS2MJuM5JDjbZKKngEw03Yb9rus xWDuEibzBcYWYAtIl5NqmQ9KrSmKAYjFKDZywzeG4yJK9XRiLgiDGux40 txdvoof4vpYdze0ciwmC05K2pZcs7J+RSUThefor6nwPJJ9HCuLUJkx+G g==; X-IronPort-AV: E=McAfee;i="6400,9594,10373"; a="302985841" X-IronPort-AV: E=Sophos;i="5.91,290,1647327600"; d="scan'208";a="302985841" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 05:02:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,290,1647327600"; d="scan'208";a="534054638" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 10 Jun 2022 05:02:17 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 0FF61F8; Fri, 10 Jun 2022 15:02:21 +0300 (EEST) From: Andy Shevchenko To: Greg Kroah-Hartman , Mark Brown , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Cc: "Rafael J. Wysocki" , Andy Shevchenko , "Rafael J . Wysocki" Subject: [PATCH v2 2/2] spi: Use device_find_any_child() instead of custom approach Date: Fri, 10 Jun 2022 15:02:19 +0300 Message-Id: <20220610120219.18988-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220610120219.18988-1-andriy.shevchenko@linux.intel.com> References: <20220610120219.18988-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org We have already a helper to get the first child device, use it and drop custom approach. Signed-off-by: Andy Shevchenko Reviewed-by: Rafael J. Wysocki Acked-by: Mark Brown --- v2: added tag (Rafael) drivers/spi/spi.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index ea09d1b42bf6..b04be04dddfa 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2613,11 +2613,6 @@ int spi_slave_abort(struct spi_device *spi) } EXPORT_SYMBOL_GPL(spi_slave_abort); -static int match_true(struct device *dev, void *data) -{ - return 1; -} - static ssize_t slave_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -2625,7 +2620,7 @@ static ssize_t slave_show(struct device *dev, struct device_attribute *attr, dev); struct device *child; - child = device_find_child(&ctlr->dev, NULL, match_true); + child = device_find_any_child(&ctlr->dev); return sprintf(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL); } @@ -2644,7 +2639,7 @@ static ssize_t slave_store(struct device *dev, struct device_attribute *attr, if (rc != 1 || !name[0]) return -EINVAL; - child = device_find_child(&ctlr->dev, NULL, match_true); + child = device_find_any_child(&ctlr->dev); if (child) { /* Remove registered slave */ device_unregister(child);