Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4407159ioa; Wed, 27 Apr 2022 03:13:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgnsLtN8K62ap/JFj0BnuPewPDQw9+CoRH3AhzR1aShZgRQzWX5KsnvdPjAXG2+IKK9gCU X-Received: by 2002:a17:90b:1e10:b0:1d9:a68a:144f with SMTP id pg16-20020a17090b1e1000b001d9a68a144fmr10117538pjb.17.1651054403914; Wed, 27 Apr 2022 03:13:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651054403; cv=none; d=google.com; s=arc-20160816; b=kJPGn9LVUebQyXOBYuSy86J5EOrA5Zyf44UsC/gPFPLx4F0K5cBYhYZib9/swOkmty 0THiiErwa2Dq1KTH9m03Jby5mDAoube0emRwvSIOuixn2EM4WLO29rPiOyeRxdU44bpD VZomXIge5k3D1MRyO09gQNc8KksSJGOoa79Hz6S5f246vV6jK3OPJBgWafbj8atkv2Qg PMw83OHTrjY21peioBcw9PsiHtRYuywSsshkfLkDqXkOC9XkB4XasKH3jTHPHbKJoEBL fEtTnkXPp3IqgsBuosci0b73AK4/RFflN0emJJ6V4mdSyxNK9phadqGdF54ZT6m4yOhs 05KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=hRvdXNRsQ2KJBLAGdH1x/uj/Z+r51wqOTF2pGTyqHK0=; b=DiawFq6OesCRwhl1mrQoFNobXS1pDhnl36Hz/La1+CCsurDPef4woMg12D6AGYlvmR k15iM1NBK7/11/iH/otk59VmnxlqUlMYiQMlLJzku96rjOgjlsCx1AdeZexQhGsQJD5h rUNYu7LdP05GxSMusYG9AsiJ/8jcmjD+vGuDxUlnuYSzowShg3R+YXM+ofi8tDKbHBbx VgDYFVLc2KYBpfdEWmTkJhrPPpKcHyGN9+drcnNPAzR6FU0pj8Gvb+S3dKOi8IhoJHgz 5uh48ML4FLL7dR/2fJOxH4Oqs/AXkUmo44OQiMxt9g7KfjlzF4gvW9JlVPeevKosPBla Xo8A== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x3-20020a1709028ec300b00153b2d1643bsi1198381plo.67.2022.04.27.03.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:13:23 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 834FF21762D; Wed, 27 Apr 2022 02:35:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348316AbiDZQ2r (ORCPT + 99 others); Tue, 26 Apr 2022 12:28:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352977AbiDZQ2p (ORCPT ); Tue, 26 Apr 2022 12:28:45 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5DD90169417 for ; Tue, 26 Apr 2022 09:25:36 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1E12B23A; Tue, 26 Apr 2022 09:25:36 -0700 (PDT) Received: from e120937-lin (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D78D63F73B; Tue, 26 Apr 2022 09:25:34 -0700 (PDT) Date: Tue, 26 Apr 2022 17:25:28 +0100 From: Cristian Marussi To: Sudeep Holla Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.quinlan@broadcom.com, Jonathan.Cameron@huawei.com, f.fainelli@gmail.com, etienne.carriere@linaro.org, vincent.guittot@linaro.org, souvik.chakravarty@arm.com Subject: Re: [PATCH 02/22] firmware: arm_scmi: Make protocols init fail on basic errors Message-ID: References: <20220330150551.2573938-1-cristian.marussi@arm.com> <20220330150551.2573938-3-cristian.marussi@arm.com> <20220426153528.bhskpchq2huhjtjk@bogus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220426153528.bhskpchq2huhjtjk@bogus> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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 On Tue, Apr 26, 2022 at 04:35:28PM +0100, Sudeep Holla wrote: > On Wed, Mar 30, 2022 at 04:05:31PM +0100, Cristian Marussi wrote: > > Bail out of protocol initialization routine early when basic information > > about protocol version and attributes could not be retrieved: failing to > > act this way can lead to a successfully initialized SCMI protocol which > > is in fact not fully functional. > > > > Signed-off-by: Cristian Marussi > > --- > > drivers/firmware/arm_scmi/base.c | 5 ++++- > > drivers/firmware/arm_scmi/clock.c | 8 ++++++-- > > drivers/firmware/arm_scmi/perf.c | 10 +++++++--- > > drivers/firmware/arm_scmi/power.c | 10 +++++++--- > > drivers/firmware/arm_scmi/reset.c | 10 +++++++--- > > drivers/firmware/arm_scmi/sensors.c | 4 +++- > > drivers/firmware/arm_scmi/system.c | 5 ++++- > > 7 files changed, 38 insertions(+), 14 deletions(-) > > Hi Sudeep, thanks for the review first of all... > > @@ -370,7 +372,9 @@ static int scmi_clock_protocol_init(const struct scmi_protocol_handle *ph) > > if (!cinfo) > > return -ENOMEM; > > > > - scmi_clock_protocol_attributes_get(ph, cinfo); > > + ret = scmi_clock_protocol_attributes_get(ph, cinfo); > > + if (ret) > > + return ret; > > Does this result in removal of scmi_dev associated with devm_* calls ? > Otherwise we may need to free the allocated buffers ? I am not sure > if the dev here is individual scmi_dev or the platform scmi device. > I assume latter and it is unlikely to be removed/freed with the error in > the above path. > > Similarly in couple of other instances/protocols. So, ph->dev used in the above devm_ is indeed the arm_scmi platform device and I was *almost* gonna tell you 'Good catch', BUT then, rereading my own code (O_o), I saw/remembered that when a protocol instance is initialized on it first usage, there is indeed a devres_group internally managed by the SCMI core, so that: scmi_get_protocol_instance() @first_protocol_usage (refcount pi->users): --> scmi_get_protocol() // just in case was LKM proto --> scmi_alloc_init_protocol_instance() gid = devres_open_group(handle->dev, NULL, GFP_KERNEL); ret = pi->proto->instance_init(&pi->ph); ====>>> i.e. scmi_clock_protocol_init(ph) if (ret) goto clean; ..... clean: devres_release_group(handle->dev, gid); So basically all that happens at initialization time in scmi_clock_protocol_init, BUT also everything that happens implicitly inside scmi_alloc_init_protocol_instance during that protocol initialization (like the events registration) is undone on failure transparently by the SCMI core init/free management functions (via devres_ groups...) All of the above is because each protocol is initialized only once on its first usage, no matter how many SCMI driver users (and scmi_devs) are using it...only in case (unsupported) we have multiple SCMI instances (platforms) there will be one instance of protocol initialized per SCMI server. ... having said that, now I'll go and double check (test) this behaviour since I even had forgot about having implemented this kind of design :P Thanks, Cristian