Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1001254rwb; Thu, 8 Dec 2022 05:45:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf51PZArpBKHoT6V3B3TZB7djfrW2Hz0/RKR+Tnpjj9krSygSTNhaHYdobcekcVpPbfTBnxh X-Received: by 2002:aa7:d558:0:b0:461:eea0:514c with SMTP id u24-20020aa7d558000000b00461eea0514cmr23905509edr.296.1670507142226; Thu, 08 Dec 2022 05:45:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670507142; cv=none; d=google.com; s=arc-20160816; b=Sjhh9VvKdzfQWKlOfIU2bMSf/sBV8Mz0WaT/lotiVBMVS0fX+gBKW0/WZ22WlKreWe NLrZ7ZQIEWuqGSt6Q9/Lo2WBimzZ0Ptpt1uV7h/uWK5WlHKNqF5A91e9klzsU3I4YmYm x28JKxOASi5m9tZnHYRA+ENWBzewkDjCvUSn5diRUvUBbGZBjAV5n4IDhvafJqviKzfk C+Nq72qu7Op4K+8/ktgu+hfX5WftDrPqNoGnnoqfhtteRRgodpiXziDaiiA0WI008uQO P3XeNKLlEAyF9IzbTQUX9QE782Hy5oXT+EOeYl67+wKuX1EAmBYvm44grZeZnLQ2zLxI BUxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=JZ7np5caI4unEEBvRTaWL2Uygj5hC6MVtGCTSMAC2xE=; b=A/LQ+KaETWGGQnW5EDwq7zA5BkPu80TSCcqpob0hRQ7WMeZKf9p/jbmfQFegN+h7p0 sKfugWNbkFJwRK/+p91az3dXXjNGa6Ga2kyYOkgmdqz7dVIphcNvjeYPJ2Hd/lPwfO8y RA5stJaqsZUI/3beV9AZ5hjT1AEjbET2PKiblyZPl/ru6Ai/ZlX5FcxYIPc0OpW5BW8S quJYid4ZPaess7A20+xt/fl7E5gm6tQgngAixKQOcreSkhM1aaUlMcbJmRJ9g0T83l2r sOcFTnV+8RaXoOgwnCayNPrmpaORv/uMVXxqAtFOr4FSqe/zMjtRMTUigYNSENxHD3eb y5uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OwykP3QW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b8-20020aa7c6c8000000b00469054c7246si5811020eds.506.2022.12.08.05.45.24; Thu, 08 Dec 2022 05:45:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OwykP3QW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230132AbiLHM67 (ORCPT + 72 others); Thu, 8 Dec 2022 07:58:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbiLHM66 (ORCPT ); Thu, 8 Dec 2022 07:58:58 -0500 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DAC87F8BD; Thu, 8 Dec 2022 04:58:57 -0800 (PST) Received: by mail-lj1-x22c.google.com with SMTP id q7so1459908ljp.9; Thu, 08 Dec 2022 04:58:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JZ7np5caI4unEEBvRTaWL2Uygj5hC6MVtGCTSMAC2xE=; b=OwykP3QWxZHL7mgwuoBNcNvCPcBbQrgf6edkkSg8iAP6D7MG34XPYD2JI7b2wLIeDd gChUZuSv5RSGLBno4s5Vn87JZhr2tKNIXHCcFcoOztrWSds3oUjdDFBSg8ARvbVe1G2O GYIrFeWCRGg7bOFtVISK+RMieqTxA6mccGaGdQvg39rKtPKrGruYom3NMZxAOeFakkKd 2pNWD7naBB/4lOUOI7egs15/1+nP8Es/eytoWEkNsbejPT/JO/FPRaoupnn3Z8BOvNM2 bH1scsjlx9323enLvf3PXOCpNzBPVSoj/CQfQ8FEA0++3tSkEcu/GVJSUh9sDETEKyfG yMcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JZ7np5caI4unEEBvRTaWL2Uygj5hC6MVtGCTSMAC2xE=; b=VKIXHypMH/y6ZYO4kp8/8/OXGlQQqVXZhjU9mTFMILyRcw3q+ZuYW2Cj/BFadVLEZU llLgx/Z8NefDnGffvv/Y7ptshUzJ4NVkDZQpFaVB4cO9nmZw6TqC15GiovyUQGA0XzQ5 DZVeC/xDXSxP7ptrzM23cEWtyNw0/6GocRhneqyrf1gd4Fc1tki11eLab7A+HFuDDmE/ Z/5qIDuTO/fJj3jv2WfdZG+kvMNFHXBR77vTZkTiZiki0mXP0wRWqqoafRMXMLz0uhUx O31C7ix0oaRdsPgNEmpZjfi6RtQIi9oAC2+Jk34myPl9PI70T5Mh60TrRGvEjSNM1aHS cSog== X-Gm-Message-State: ANoB5pkHLvp/PMLlgGswVA0dkyHnNaWXhgGWCL6kU9+mEKCjM4Lo1M1M 6g3EKndnBWFvV0NKQgFVnt1oJzWSOX+qQ4S0hBw= X-Received: by 2002:a2e:7c17:0:b0:27a:17d5:2964 with SMTP id x23-20020a2e7c17000000b0027a17d52964mr2520757ljc.488.1670504335717; Thu, 08 Dec 2022 04:58:55 -0800 (PST) MIME-Version: 1.0 References: <20221205085351.27566-1-tmaimon77@gmail.com> <20221205085351.27566-3-tmaimon77@gmail.com> In-Reply-To: From: Tomer Maimon Date: Thu, 8 Dec 2022 14:58:44 +0200 Message-ID: Subject: Re: [PATCH v2 2/2] mmc: sdhci-npcm: Add NPCM SDHCI driver To: Andy Shevchenko Cc: Adrian Hunter , ulf.hansson@linaro.org, avifishman70@gmail.com, tali.perry1@gmail.com, joel@jms.id.au, venture@google.com, yuenn@google.com, benjaminfair@google.com, skhan@linuxfoundation.org, davidgow@google.com, pbrobinson@gmail.com, gsomlo@gmail.com, briannorris@chromium.org, arnd@arndb.de, krakoczy@antmicro.com, openbmc@lists.ozlabs.org, linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks a lot, Adrian and andy! Appreciate it On Wed, 7 Dec 2022 at 18:49, Andy Shevchenko wrote: > > On Wed, Dec 7, 2022 at 3:49 PM Adrian Hunter wrote: > > On 7/12/22 15:25, Andy Shevchenko wrote: > > > On Wed, Dec 7, 2022 at 3:01 PM Tomer Maimon wrote: > > >> On Mon, 5 Dec 2022 at 16:33, Adrian Hunter wrote: > > >>> On 5/12/22 16:17, Andy Shevchenko wrote: > > >>>> On Mon, Dec 5, 2022 at 4:14 PM Andy Shevchenko > > >>>> wrote: > > >>>>> On Mon, Dec 5, 2022 at 3:41 PM Adrian Hunter wrote: > > >>>>>> On 5/12/22 15:25, Andy Shevchenko wrote: > > >>>>>>> On Mon, Dec 5, 2022 at 1:20 PM Tomer Maimon wrote: > > ... > > > >>>>>>> devm_ is problematic in your case. > > >>>>>>> TL;DR: you need to use clk_get_optional() and clk_put(). > > >>>>>> > > >>>>>> devm_ calls exactly those, so what is the issue? > > >>>>> > > >>>>> The issue is the error path or removal stage where it may or may be > > >>>>> not problematic. To be on the safe side, the best approach is to make > > >>>>> sure that allocated resources are being deallocated in the reversed > > >>>>> order. That said, the > > >>>>> > > >>>>> 1. call non-devm_func() > > >>>>> 2. call devm_func() > > >>>>> > > >>>>> is wrong strictly speaking. > > >>>> > > >>>> To elaborate more, the > > >>>> > > >>>> 1. call all devm_func() > > >>>> 2. call only non-devm_func() > > >>>> > > >>>> is the correct order. > > >>> > > >>> 1. WRT pltfm_host->clk, that is what is happening > > >>> 2. WRT other resources that is simply not always possible because not every resource is wrapped by devm_ > > >>> e.g. mmc_alloc_host() / mmc_free_host() > > >> I little confused about what to decide, should I use only > > >> non-devm_func because mmc_alloc_host() / mmc_free_host() is not > > >> warrped with devm_? > > > > > > It is up to you how to proceed. I pointed out the problem with your > > > code which may or may not be fatal. > > > > > > If you want to solve it, there are several approaches: > > > 1) get rid of devm_ completely; > > > 2) properly shuffle the ordering in ->probe(), so all devm_ calls are > > > followed by non-devm_; > > > 3) wrap non-devm_ cals to become managed (see > > > devm_add_action_or_reset() approach); > > > 4) fix SDHCI / MMC layer by providing necessary devm_ calls and/or fix > > > sdhci_pltfm_register() to handle the clock. > > > > I can take care of sdhci_pltfm when I next have some time. > > Otherwise it looks OK to me, so I am acking it. > > Thank you! > > > > Personally, the list order is from the least, what I prefer, to the > > > most (i.o.w. I would like to see rather 4) than 1) to be implemented). > > > > > >>>> Hence in this case the driver can be worked around easily (by > > >>>> shuffling the order in ->probe() to call devm_ first), but as I said > > >>>> looking into implementation of the _unregister() I'm pretty sure that > > >>>> clock management should be in sdhci-pltfm, rather than in all callers > > >>>> who won't need the full customization. > > >>>> > > >>>> Hope this helps to understand my point. > > >>>> > > >>>>>>> Your ->remove() callback doesn't free resources in the reversed order > > >>>>>>> which may or, by luck, may not be the case of all possible crashes, > > >>>>>>> UAFs, races, etc during removal stage. All the same for error path in > > >>>>>>> ->probe(). > > >>>>> > > >>>>> I also pointed out above what would be the outcome of neglecting this rule. > > ... > > > >>>>>>>>> Why can't you use sdhci_pltfm_register()? > > >>>>>>>> two things are missing in sdhci_pltfm_register > > >>>>>>>> 1. clock. > > >>>>>>> > > >>>>>>> Taking into account the implementation of the corresponding > > >>>>>>> _unregister() I would add the clock handling to the _register() one. > > >>>>>>> Perhaps via a new member of the platform data that supplies the name > > >>>>>>> and index of the clock and hence all clk_get_optional() / clk_put will > > >>>>>>> be moved there. > > >> Do you mean to add it to sdhci_pltfm_register function? if yes I > > >> believe it will take some time to modify sdhci_pltfm_register > > >> I prefer not to use sdhci_pltfm_register. > > > > > > In the Linux kernel we are trying hard to avoid code duplication. Why > > > do you need it to be open coded? (Yes, I heard you, but somebody > > > should fix the issues with that funcion at some point, right?) > > > > > >>>>>>>> 2. Adding SDHCI_CAN_DO_8BIT capability according the eMMC capabilities. > > >>>>>>> > > >>>>>>> All the same, why can't platform data be utilised for this? > > -- > With Best Regards, > Andy Shevchenko