Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2261107ybt; Tue, 16 Jun 2020 01:03:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwB1bddzWHd/2gydhSDi8lMyX/A8ujJoxyi5VnzmZi0NKDhqdik5Gr026owqVI9oxrxZxH8 X-Received: by 2002:a50:98c1:: with SMTP id j59mr1530067edb.120.1592294599520; Tue, 16 Jun 2020 01:03:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592294599; cv=none; d=google.com; s=arc-20160816; b=yedbtnHeJhniG22xwUSX4CNT0u8+8YNoOUWQNdUn9/vNidroLvtFzWBZYQj3hVy8EX vaXBfFhKqBQQAcmVv1v2WY+G7GADSHW1sbBwfgxrZfEoTyagrHcknjXV4/r+lg/ezKzX 6y5vm2/eST3zk2M/WWGqsfrwtuA2uu3jCiI0MVT4dgTN5TOx+dy9rPLkvBLhRwUCrIr2 kDbW97m7c5oJBjAKF73tCar3vzQNkcyPm/zawkpDH8zOoAFBK5HLWouJI4cSIze2QxN3 g9NC02z4pAUHx7qEhgbR2mulfBX7Lgx/jdb6GSgmPO3Kz0eVZgCAClNKZYoECAmFy/7d r8lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=zkpEUYkVmnjSkCa7M9yUMVXxz2rW/49cI/qWtv7pReE=; b=rqAmhR8nVDXN2i7zbwEgv8rLJbGI0w1xKlG/rvH1dbrBK9hrq8OohlxF0njI8Fae9p mhJ4DiCTTJfM0u1QqtZ2nOBojPrCxhmBE7nXHoZHozMNoETlJDUrf61DXiNOgGMTRwx6 EDgNCLmY22oNynQas1skdhDUqULLYV65GY54HRWPvUGBvdefD6AizQNkb8KhiMBPyFe9 wc33/Smzf8JpywqZO7mCt/YweEOLx9pZ0QKoKrK9ifvJOrDw96jJS4U+boP8X+8aa6HQ feOA1XcITFpjk3F9EcVZEsM4vaf/4wO9SoC1/tLhy1PhoCQXhb97oHjVudvSMV+gckmm m37w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D7KPqbyy; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a22si10784777ejx.579.2020.06.16.01.02.56; Tue, 16 Jun 2020 01:03:19 -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=pass header.i=@linaro.org header.s=google header.b=D7KPqbyy; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726296AbgFPH6j (ORCPT + 99 others); Tue, 16 Jun 2020 03:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726099AbgFPH6i (ORCPT ); Tue, 16 Jun 2020 03:58:38 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7F3BC05BD43 for ; Tue, 16 Jun 2020 00:58:37 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id t194so2023803wmt.4 for ; Tue, 16 Jun 2020 00:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=zkpEUYkVmnjSkCa7M9yUMVXxz2rW/49cI/qWtv7pReE=; b=D7KPqbyyWMy/8cI1heqRPj1ri2gK0clJjrKnUIcmJgW8gC4xFRXoVkloHJ/X0Sd1tK hiZYR/PMNBPZqUmF7TX7kF1pM8zZA1WtxgF4B3+V+4vhB5Enx/YebaUN4XqEnhtIngBy VFe05tzUWoPuvpqORVtOaVxbY3qvucvjXAivvhc1EabFYwRxK2/Hazc4N8Xv29w7Mu2n Sx1hFRVipzrScU+TKliNjyHgzGStL2J17vca/NfOxjafLbskypg1eGkhjPHqelvT2WVJ UTf7Cxg7qfYe2IzJeXtwnjYrZPm46e934fPpPyO4e94fY+6C/uBGh5b2rAM/4PoKrAWn d9qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=zkpEUYkVmnjSkCa7M9yUMVXxz2rW/49cI/qWtv7pReE=; b=nWLxPEDB9P2zFQhfrpN1SBY0G/HPNzoEwPsHCra5+BJLgO8kqTEEWcvHNTF0eVLmAQ VK4aqWzz2vTs8oEkQz9PbmH6+r0Htp4wYy4CgADBo0Af0GhvwqqR1kKYtvr56uMjupg7 gUgAYIQcyFm9oXc7WaB7ds/BMCQOCKwiVwrlgQfZXp5jH2NBL4CJ2k1GtfIskMNfhcJN 767O8M9sC6aUG5dbCv+dFuZNfKbYLgQiblkQ/UsSqN/k6/gLESP7UdjgOq+wOGDoEjeT Oy2uyYR9ixcru5F2AJ/JhmHrXFqrPgcg1UxVpK/6n/IholeEw5ST5gny21hUgcV4Pau3 fRuw== X-Gm-Message-State: AOAM530GWo/rZeryZqOEUkhNOYByiLKHJRd9BEF8dACFdJXvLkFK6gZD uTDBPGBMUmVxxzD0y131UoLCEC2mviU= X-Received: by 2002:a1c:6056:: with SMTP id u83mr1800951wmb.138.1592294316432; Tue, 16 Jun 2020 00:58:36 -0700 (PDT) Received: from dell ([109.180.115.156]) by smtp.gmail.com with ESMTPSA id 104sm29488309wrl.25.2020.06.16.00.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 00:58:35 -0700 (PDT) Date: Tue, 16 Jun 2020 08:58:34 +0100 From: Lee Jones To: Charles Keepax Cc: linux-kernel@vger.kernel.org, patches@opensource.cirrus.com Subject: Re: [PATCH v2 1/2] mfd: mfd-core: Add mechanism for removal of a subset of children Message-ID: <20200616075834.GF2608702@dell> References: <20200615150722.5249-1-ckeepax@opensource.cirrus.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200615150722.5249-1-ckeepax@opensource.cirrus.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 15 Jun 2020, Charles Keepax wrote: > Currently, the only way to remove MFD children is with a call to > mfd_remove_devices, which will remove all the children. Under > some circumstances it is useful to remove only a subset of the > child devices. For example if some additional clean up is required > between removal of certain child devices. > > To accomplish this a tag field is added to mfd_cell, and a > corresponding mfd_remove_devices_by_tag function is added to > remove children with a specific tag. This allows a good amount of > flexibility in which child devices a driver wishes to remove, as a > driver could target specific drivers or a large group. Allowing other > use-cases such as removing drivers for functionality that is no longer > required. > > Some investigation was done of using the mfd_cell name and id fields, > but it is hard to achieve a good level of flexibility there, at least > without significant complexity. Since the id gets modified by the core > and can even by automatically generated. Using the name alone would > work for my usecase but it is not hard to imagine a situation where it > wouldn't. > > Signed-off-by: Charles Keepax > --- > > Following on from our discussions here: │·················· > │·················· > https://lore.kernel.org/lkml/20200122110842.10702-2-ckeepax@opensource.cirrus.com/#t │·················· > │·················· > Happy to discuss other approaches as well, but this one was quite │·················· > appealing as it was very simple but affords quite a lot of flexibility. │·················· What about this? diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c index f5a73af60dd40..a06e0332e1e31 100644 --- a/drivers/mfd/mfd-core.c +++ b/drivers/mfd/mfd-core.c @@ -283,7 +283,7 @@ int mfd_add_devices(struct device *parent, int id, } EXPORT_SYMBOL(mfd_add_devices); -static int mfd_remove_devices_fn(struct device *dev, void *data) +static int mfd_remove_devices_fn(struct device *dev, void *level) { struct platform_device *pdev; const struct mfd_cell *cell; @@ -294,6 +294,9 @@ static int mfd_remove_devices_fn(struct device *dev, void *data) pdev = to_platform_device(dev); cell = mfd_get_cell(pdev); + if (cell->level && (!level || cell->level != *level)) + return 0; + regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies, cell->num_parent_supplies); @@ -303,7 +306,11 @@ static int mfd_remove_devices_fn(struct device *dev, void *data) void mfd_remove_devices(struct device *parent) { + int level = MFD_DEP_LEVEL_HIGH; + device_for_each_child_reverse(parent, NULL, mfd_remove_devices_fn); + device_for_each_child_reverse(parent, &level, mfd_remove_devices_fn); } EXPORT_SYMBOL(mfd_remove_devices); No need for special calls from the parent driver in this case. Just a requirement to set the cell's dependency level. -- Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog