Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1540558ybk; Sat, 16 May 2020 14:53:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxWnc/0d92pZWh7rvUK72rYJrirU20nTYQ133bDYd15y5z+8UrT2bYfIXtdH32QHUaIMTo X-Received: by 2002:a17:906:7a4f:: with SMTP id i15mr8676894ejo.71.1589666001526; Sat, 16 May 2020 14:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589666001; cv=none; d=google.com; s=arc-20160816; b=qTaZ9mKH1LDRPMIGEzt0lnXXFCbcbJy4itXtBJlpr4NRZJstmY6gvTwVRZY+EG8rZ5 dJfKbDmPg0KlUnewljYOcHfP7YJzbDpXPMo2J8JjNzWZJhWd8fJ6gKGyFPYkAJEhf7J3 klBzhTaniZ6HQwEZmbDmSZDoDKP7Yrk1uLSr+c8fmk9NDCzD8R47fxHtD5DSHVhz/aEy Ndm/AB41AZLPJPDpqVvq+sK6KV2lcsOGgLRb42OT1xJiUcXR71SMhGJ5ToH3nU8MXESd lsAwBmVxcYBIc0FGfzg/425UesrOVTlnVj7qldsB+2QF0sgS6IZ0bLpyN5VCVqeg0pCc FchQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oIsUOHTqtqa7F5+gZuYIGs0fcUI70HLM4r/HBVMSNE4=; b=z7PcPonWme/7LFSk/gKh88VeP7ZqoaZiiMQ35Kwe0vB1LLkjaGyRiGl3wxljgXQ+gt KT6v/J/NZm+memEgkjAM5/1wFZYVQ9aGqWgbSqZ1RH9XrNRIQibxsmj7vDHAB9/nibX/ TsEt8KDue/c2AEWq8u1vOmeODc3VF0e4uI6yffck+yZKk/HgST2f0c9+7Pxp7PYcIfsE 5H4vqOLq9+2G6G45C4QBJ683Vl8fZsccLa+ZfLj2MLo1QS1HbX4SZ00hc5jywrcSLORO qRbGwHH3qjNFA61lknYBzM4H0FaU+5ndSHHU05Utz4yL09dvCMgG22oOFsCDktO1i0Sf Ul5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b="SnP/VdcT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dj17si3400554edb.556.2020.05.16.14.52.58; Sat, 16 May 2020 14:53:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b="SnP/VdcT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgEPVv0 (ORCPT + 99 others); Sat, 16 May 2020 17:51:26 -0400 Received: from outils.crapouillou.net ([89.234.176.41]:46656 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbgEPVv0 (ORCPT ); Sat, 16 May 2020 17:51:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1589665870; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oIsUOHTqtqa7F5+gZuYIGs0fcUI70HLM4r/HBVMSNE4=; b=SnP/VdcTCWwehlzF6AxGZRQCTLuWnVWs/BS9LSnFHXVQLHPaC2YuH1GEIWfwNEqP9w/cMY vuaNQQe+1XNxJtuyzslQ3sTD5pcSZuPInly1z/qhU7uVOOQo6QvwgBIj+1XbsIhGiP61LR 2TwnChhRIzWuT4E/EQAH2KA3rABiF9U= From: Paul Cercueil To: David Airlie , Daniel Vetter , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: od@zcrc.me, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH 03/12] component: Support binding with no matches Date: Sat, 16 May 2020 23:50:48 +0200 Message-Id: <20200516215057.392609-3-paul@crapouillou.net> In-Reply-To: <20200516215057.392609-1-paul@crapouillou.net> References: <20200516215057.392609-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support binding the master even though no components have been registered. This permits to support cases where components are optional. Signed-off-by: Paul Cercueil --- drivers/base/component.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index e97704104784..a9de7ee1677f 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -100,7 +100,7 @@ static int component_devices_show(struct seq_file *s, void *data) seq_printf(s, "%-40s %20s\n", "device name", "status"); seq_puts(s, "-------------------------------------------------------------\n"); - for (i = 0; i < match->num; i++) { + for (i = 0; !!match && i < match->num; i++) { struct component *component = match->compare[i].component; seq_printf(s, "%-40s %20s\n", @@ -184,6 +184,11 @@ static int find_components(struct master *master) size_t i; int ret = 0; + if (!match) { + dev_dbg(master->dev, "No components\n"); + return 0; + } + /* * Scan the array of match functions and attach * any components which are found to this master. @@ -218,10 +223,12 @@ static void remove_component(struct master *master, struct component *c) { size_t i; - /* Detach the component from this master. */ - for (i = 0; i < master->match->num; i++) - if (master->match->compare[i].component == c) - master->match->compare[i].component = NULL; + if (master->match) { + /* Detach the component from this master. */ + for (i = 0; i < master->match->num; i++) + if (master->match->compare[i].component == c) + master->match->compare[i].component = NULL; + } } /* @@ -470,10 +477,12 @@ int component_master_add_with_match(struct device *dev, struct master *master; int ret; - /* Reallocate the match array for its true size */ - ret = component_match_realloc(dev, match, match->num); - if (ret) - return ret; + if (match) { + /* Reallocate the match array for its true size */ + ret = component_match_realloc(dev, match, match->num); + if (ret) + return ret; + } master = kzalloc(sizeof(*master), GFP_KERNEL); if (!master) @@ -557,6 +566,10 @@ void component_unbind_all(struct device *master_dev, void *data) if (!master) return; + /* No match, nothing to unbind */ + if (!master->match) + return; + /* Unbind components in reverse order */ for (i = master->match->num; i--; ) if (!master->match->compare[i].duplicate) { @@ -640,6 +653,10 @@ int component_bind_all(struct device *master_dev, void *data) if (!master) return -EINVAL; + /* No match, nothing to bind */ + if (!master->match) + return 0; + /* Bind components in match order */ for (i = 0; i < master->match->num; i++) if (!master->match->compare[i].duplicate) { -- 2.26.2