Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1068992rda; Mon, 23 Oct 2023 01:04:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeoSKqXTXBGKBQ2N3gZ8hLgo92CnSfV6acKCrvVeRuACmIrXPTxhlKqXpIGnNBJ635MMCf X-Received: by 2002:a05:6a00:987:b0:6be:1f19:e604 with SMTP id u7-20020a056a00098700b006be1f19e604mr11076359pfg.21.1698048257541; Mon, 23 Oct 2023 01:04:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698048257; cv=none; d=google.com; s=arc-20160816; b=AUjVrH6x1BoYG3gLohXTPJH7xrJ83u7HuwiX2mRktE0vDblWHa9lOQRpr4U6OBpOgz zIqLIYQkuaTw85KXiH6GIEqAWuH7w7wCOJIyvUAYyJX0xiEA7dCXGS3aq1Lmdn5YJOF4 GyV0vUQ2Kf6Dg3gq2EgSjAHUVnmTXErBgC90GwFpJJMK92a7ZzvcCzH/TX4l+pvp5qIU 878d5/E4Th2v8E7w0k5NaxIvehSJoNLMZE1A7WAr3speRBL2DltKKfl1Z2tby23f4UPd N+r8vyDDpFmcYnToIn+/CtWpH5MpTcsYs/XEa9uqx+cjYyK9QHalh0NY+dI68dBuPeBt KScw== 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=gmB9mDTwiF3uEH0iaSmju1hjjf2PC63Y5fnQXGlfFvY=; fh=AsBFNF2eWd4qCekJPWqACS5oQt+/GtRpUh/RA+MfODQ=; b=Ckv8Ty+SIcNtt9fVFddAkN0/qAn4zi4sxdac1y4z8Xa+eBHnimGvLPt4swMMRAI9Oe isN1oJjlhRgEoPorYz1mBxeVH/ExJeY/aGuaaVcHo4Z1IH6XfJ6i7gaBbkNPR/2xFsSN ms+dbR3YhWdQqJAsPxRe7MfrR4RshYtLNhKfhKOTrS50xa9T2AOhabNOMufYq/t8kFRQ qdwLHD3rib15F9dqHdv8gexnJ5al6xG38+r0ExZURqYvqAKxqdIszcVTq0vIyCbU+CN9 fR7h8NqkSQrJg0M350Rz5HRRWVcEJhr2Iad4Z5afTet7G/+OBH0YVbi9z9pRCXjoMAZD Xnvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fu7Fm2CW; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id fb24-20020a056a002d9800b00690dbd360basi6077987pfb.152.2023.10.23.01.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 01:04:17 -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=@linaro.org header.s=google header.b=fu7Fm2CW; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 18814805937C; Mon, 23 Oct 2023 01:04:15 -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 S229498AbjJWIED (ORCPT + 99 others); Mon, 23 Oct 2023 04:04:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjJWIEA (ORCPT ); Mon, 23 Oct 2023 04:04:00 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F5D4A1 for ; Mon, 23 Oct 2023 01:03:58 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-d9a3d737d66so2233751276.2 for ; Mon, 23 Oct 2023 01:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698048237; x=1698653037; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gmB9mDTwiF3uEH0iaSmju1hjjf2PC63Y5fnQXGlfFvY=; b=fu7Fm2CWDTbU4vgkZvk0KUscLqzKdSu6257lMymgRY9sILLbrOqdqyinFyrNaDGfE4 m1nBqXpywvnoLTZ1tRewNBSZuvo0XQ+12uYKvMrvPBxGG6bx/sxoYOdOPh1942HSpuTq che/cfCX5eANbAMk8+pZl6fzmuYHd9y9Z3iqTxGENKMe9e8/YxwvwPX0JLweZiyUogDy vIXBTWsMpWbolKvbLfxoo8f3IWF0MrQ6oXZmiz6vO8qDTYgJuJzAh4X/JdgyJhSthmN9 mFGCuOs8ufYglvDsYWHA9busqoiS/wJeSXpd2VMSWGMLQafa3RJ8VlV6OPBIbGgo2tEJ qkVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698048237; x=1698653037; 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=gmB9mDTwiF3uEH0iaSmju1hjjf2PC63Y5fnQXGlfFvY=; b=ur9l0/cMPRFjLJFEhIieoLo4Vh/ZAf1HX8x4gB/hYsMqSK6NVSP6GyXxKyU9Q/J3Oo pNbDCRKTku/SqgrbWSkoXyAcQsKYRmLtDIK9mFk42IgQ18LGPxveAdx+17vK1HnUdALB NzAH8UzLzyu6VY9mVYbkLj1wB2QDugdxPHAEusyp1M43GrUThbZgE6MbAJury/+0dHId cgCvQZ7iuYhHcNPQ6kYciKQWXdIf6tiEnDpsGLm7vtMc/mp3v3RqpJXMqIfHK72H+cMK eyYnC7bJ6LNscaZEkaThHiujl+UJ+BgVTRNLmgRAOss0EJiQzf8qaiNrAY+tswUaG8fc 0JdA== X-Gm-Message-State: AOJu0YwSkbwFWVtznFRJOcwvqlcvzh4r8Bgp4DiXUNF7CtoEc9xN0WlB dzKgwEa/+L8hI+wIYiMWxytqbBPb2wmzbCzh7jEfdw== X-Received: by 2002:a25:ef4e:0:b0:d9d:116a:89c8 with SMTP id w14-20020a25ef4e000000b00d9d116a89c8mr4808003ybm.54.1698048237350; Mon, 23 Oct 2023 01:03:57 -0700 (PDT) MIME-Version: 1.0 References: <20230708072835.3035398-1-quic_jprakash@quicinc.com> <20230708072835.3035398-8-quic_jprakash@quicinc.com> <20230708165955.08c1159c@jic23-huawei> <13d5dee2-1da4-2ad0-91f8-a53b43adba2b@quicinc.com> In-Reply-To: <13d5dee2-1da4-2ad0-91f8-a53b43adba2b@quicinc.com> From: Dmitry Baryshkov Date: Mon, 23 Oct 2023 11:03:46 +0300 Message-ID: Subject: Re: [PATCH 07/11] iio: adc: Add support for QCOM PMIC5 Gen3 ADC To: Jishnu Prakash Cc: Jonathan Cameron , agross@kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linus.walleij@linaro.org, Jonathan.Cameron@huawei.com, sboyd@kernel.org, quic_subbaram@quicinc.com, quic_collinsd@quicinc.com, quic_kamalw@quicinc.com, marijn.suijten@somainline.org, andriy.shevchenko@linux.intel.com, krzysztof.kozlowski@linaro.org, Lars-Peter Clausen , Bjorn Andersson , Konrad Dybcio , Arnd Bergmann , Cosmin Tanislav , Mike Looijmans , Ramona Bolboaca , ChiYuan Huang , Ibrahim Tilki , William Breathitt Gray , Lee Jones , =?UTF-8?Q?Leonard_G=C3=B6hrs?= , Haibo Chen , linux-iio@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-msm-owner@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 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]); Mon, 23 Oct 2023 01:04:15 -0700 (PDT) On Mon, 23 Oct 2023 at 09:15, Jishnu Prakash wrote: > > Hi Jonathan, > > On 7/8/2023 9:29 PM, Jonathan Cameron wrote: > > On Sat, 8 Jul 2023 12:58:31 +0530 > > Jishnu Prakash wrote: > >> + > >> + ret = adc5_get_fw_data(adc); > >> + if (ret < 0) { > >> + dev_err(adc->dev, "adc get dt data failed, ret=%d\n", ret); > >> + return ret; > >> + } > >> + > >> + for (i = 0; i < adc->num_sdams; i++) { > >> + ret = devm_request_irq(dev, adc->base[i].irq, adc5_gen3_isr, > >> + 0, adc->base[i].irq_name, adc); > >> + if (ret < 0) { > >> + dev_err(adc->dev, "Getting IRQ %d failed, ret=%d\n", adc->base[i].irq, ret); > >> + return ret; > >> + } > >> + } > >> + > >> + ret = adc_tm_register_tzd(adc); > >> + if (ret < 0) > >> + return ret; > >> + > >> + if (adc->n_tm_channels) > >> + INIT_WORK(&adc->tm_handler_work, tm_handler_work); > >> + > >> + indio_dev->name = pdev->name; > >> + indio_dev->modes = INDIO_DIRECT_MODE; > >> + indio_dev->info = &adc5_gen3_info; > >> + indio_dev->channels = adc->iio_chans; > >> + indio_dev->num_channels = adc->nchannels; > >> + > >> + return devm_iio_device_register(dev, indio_dev); > >> +} > >> + > >> +static int adc5_gen3_exit(struct platform_device *pdev) > >> +{ > > As you are mixing devm manged cleanup and the explicit sort the > > result is that you remove the userspace interfaces 'after' you run > > everything in here. I'm thinking disabling the channels at least > > isn't a good idea in that case. > > > > If you want to use devm (which is good) then you need to work out how > > to register additional callbacks during probe to tear down everything in > > the right order (typically the reverse of what happens in probe) > > devm_add_action_or_reset() is the way to add those extra callbacks. > > > > If not, just don't use devm for at least those bits that will end up > > running out of order (such as iio_device_register()) and manually call their > > cleanup routines instead. > > > I checked some other examples in the iio/adc/ folder, I think I see what > you mean here. It looks like drivers with a remove callback always use > iio_device_register and iio_device_unregister instead of the devm_* > variant, due to the issue with sysfs removal as you said. > > I'll update the probe and remove functions similarly, to do explicit > cleanups as required, avoiding devm_ usage for places where it should be > avoided. I think you got the message all wrong. There is nothing bad with using devm_. As a matter of fact it is a preferred form in most of the cases. However you have to be careful to tear down your device in the correct order. And as Jonathan pointed out, you might add necessary hooks manually by calling devm_add_action_or_reset(). [skipped the rest] -- With best wishes Dmitry