Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp387573rdb; Thu, 5 Oct 2023 08:43:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHp0/D0q/L2CmlHgKYtyejongeSGb+1ylQ18efiZRAYMpVshJ66e1BXicC7U4Pgkph/UB2 X-Received: by 2002:a05:6a00:1805:b0:68e:487c:c4b7 with SMTP id y5-20020a056a00180500b0068e487cc4b7mr6429152pfa.11.1696520622658; Thu, 05 Oct 2023 08:43:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696520622; cv=none; d=google.com; s=arc-20160816; b=Zq60qr2/+zSJOXEQAuDOjbipK4Qx33Ru0z2LSxBVk2HEzl45yibB3JzGsPNW0zNwX8 mP6fto8LmfrTdS9n6w70cB0H8zvtHO83myj/L45o5L/c/D429joLNmO4zD+o5ITqnlAh RY/jfSq2KFInGo2lYYpXqI/XxI5UKaqPtccQ6u1z9WL4yy0ZFwlBHr58vGfBd8lV7uav Z1jZZh2UevTzceFts4S06WzvRSUPSjEK5+26FU+Qvaqvzj/MoFT1bCMa3j6H9nHV211W YDnxwOsQmWMmF+07DcUtJ4iDzoW/SFVCaMF0EWY2eSgP3L+3C5qtnZfS5j6VUlmMnliS cBZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=oTkhhmJG+jxk+JoQwzEacdYUK4gUAFW5j1pqRExh0GY=; fh=v4PaHvUG0pCHpz2j6JC2OipQIeNY3dwkN6ITccL/odk=; b=EHvWtxaVOpugwPdfF6fgvAELEOHY0jEqS9ptnccLOYO2sW3wXboqN+9XaH22/HGv7T dHUDeHEHOy6dvO1ANqAtJ45P6v5/jpl4uwIvI9ZJFmo49ntkjSRIWd7XBqLaHt8HzcUd BjTZ7Ps274jaySBqQ/cHtQ5eQ7dJSHqsNZ1uNxIBHVd/L7Tc72Hc7WiOxxyxB/tSfHSC FNEp70p4xuB7jMkC/UjP/5EqyM5tyIXSo/VRvCUMnWqvMtG0YpemMDvVh4qgSmGlEzV0 wAzOVbAag8Wd1i48ONuPgUb23ckSI4JWGDFxSJl8X8Lu+JnDhjKne2cP2AQUfB2hxMdm EQXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Qs400x+O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id g15-20020a056a0023cf00b00691004e7db0si1690008pfc.170.2023.10.05.08.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 08:43:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Qs400x+O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4B3578258997; Thu, 5 Oct 2023 08:43:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233478AbjJEPnN (ORCPT + 99 others); Thu, 5 Oct 2023 11:43:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233553AbjJEPmt (ORCPT ); Thu, 5 Oct 2023 11:42:49 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB8210E6 for ; Thu, 5 Oct 2023 07:58:56 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id C9865FF80A; Thu, 5 Oct 2023 14:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696517935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oTkhhmJG+jxk+JoQwzEacdYUK4gUAFW5j1pqRExh0GY=; b=Qs400x+OZwvH/qBd1FBN4khJJrba3iHYM1Y/cUeCjiFJgXT1wnEaMugUfmJ5bqI1jH2IeZ ZvHnWjmruDG3H5FtX05c5jGVJamKula4KJ915ZwKlO+Kvcqix+5kIdpcCHUbvwR03DFKwO W2tJJGuS+UU3XlWI+K5UhJ8jPQTmk/YU09NpVeZjFV7KJit4pdAEomRJHQ70JBSeHgGrhc wMjTIOujZtFcWpDtwd9TN2A/fNXuUmFo7rrfwiT2BTYP7RAtt6KGoShfBgQY2NiIIy9BZp 0bZ/mjn+mRnhBG11yUr0B9fi50hDYn7CbmR/5nTOpn9p5oOopYoVaAt8fkba/Q== Date: Thu, 5 Oct 2023 16:58:52 +0200 From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Michael Walle , Thomas Petazzoni , Robert Marko , Luka Perkov , linux-kernel@vger.kernel.org, Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= Subject: Re: [PATCH v10 1/3] nvmem: core: Rework layouts to become platform devices Message-ID: <20231005165852.4619ebb2@xps-13> In-Reply-To: <20231003114326.7c61b07c@xps-13> References: <20230922174854.611975-1-miquel.raynal@bootlin.com> <20230922174854.611975-2-miquel.raynal@bootlin.com> <84ff0dd8-706e-4b44-5313-3dd77b83100c@linaro.org> <20231003114326.7c61b07c@xps-13> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 05 Oct 2023 08:43:40 -0700 (PDT) Hi Miquel, miquel.raynal@bootlin.com wrote on Tue, 3 Oct 2023 11:43:26 +0200: > Hi Srinivas, >=20 > > > +static int nvmem_dev_match_available_layout(struct device *dev, void= *data) > > > +{ > > > + struct nvmem_device *nvmem =3D to_nvmem_device(dev); > > > + > > > + return nvmem_match_available_layout(nvmem); > > > +} > > > + > > > +static int nvmem_for_each_dev(int (*fn)(struct device *dev, void *da= ta)) > > > +{ > > > + return bus_for_each_dev(&nvmem_bus_type, NULL, NULL, fn); > > > +} > > > + > > > +/* > > > + * When an NVMEM device is registered, try to match against a layout= and > > > + * populate the cells. When an NVMEM layout is probed, ensure all NV= MEM devices > > > + * which could use it properly expose their cells. > > > + */ > > > +static int nvmem_notifier_call(struct notifier_block *notifier, > > > + unsigned long event_flags, void *context) > > > +{ > > > + struct nvmem_device *nvmem =3D NULL; > > > + int ret; > > > + > > > + switch (event_flags) { > > > + case NVMEM_ADD: > > > + nvmem =3D context; > > > + break; > > > + case NVMEM_LAYOUT_ADD: > > > + break; > > > + default: > > > + return NOTIFY_DONE; > > > + } =20 > >=20 > > It looks bit unnatural for core to register notifier for its own events. > >=20 > >=20 > > Why do we need the notifier at core level, can we not just handle this = in core before raising these events, instead of registering a notifier cb? = =20 >=20 > There is no good place to do that "synchronously". We need some kind of > notification mechanism in these two cases: > * A memory device is being probed -> if a matching layout driver is > already available, we need to parse the device and expose the cells, > but not in the thread registering the memory device. > * A layout driver is being insmod'ed -> if a memory device needs it to > create cells we need to parse the device content, but I find it > crappy to start device-specific parsing in the registration handler. >=20 > So probe of the memory device is not a good place for this, nor is the > registration of the layout driver. Yet, we need to do the same > operation upon two different "events". >=20 > This notifier mechanism is a clean and easy way to get notified and > implement a callback which is also not blocking the thread doing the > initial registration. I am personally not bothered using it only > internally. If you have another mechanism in mind to perform a similar > operation, or a way to avoid this need I'll do the switch. Since I've changed the way nvmem devices and layouts are dependent in v11, I've been giving this a second thought and I think this can now be avoided. I've improved the layout registration callback to actually retrieve the nvmem device this layout is probing on and populates the dynamic cells *there* (instead of during the probe of the nvmem device itself). This way I could drop some boilerplate which is no longer necessary. It comes at a low cost: there are now two places were sysfs cells can be added. I am cleaning up all this stuff and then let you and Greg review the v12. Thanks, Miqu=C3=A8l