Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp855015rdg; Fri, 13 Oct 2023 03:20:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFf82ZqrFdYlujX0gTZmY6uA7jOu1LC4XhBXIpeQyM4ccSMhdlthZBZGUPHTigPtDwR22JR X-Received: by 2002:a17:90b:1d88:b0:269:a96:981a with SMTP id pf8-20020a17090b1d8800b002690a96981amr36657847pjb.5.1697192410336; Fri, 13 Oct 2023 03:20:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697192410; cv=none; d=google.com; s=arc-20160816; b=SS8p2rLZ2Ej0OVzta5Vi3ENnUoxvrSNqagCS8jS/LyMQahEsd+FD0mVdEngaAVvuXU 3q8EeN19YDpvoN5MKW6piXdWKq5w8rWNqg5+AiVbyx+BsKZypmwZcjciyWDJnCo540Cm pmfzaCkCvfMeCEzfW3TEMWXFrr4/fyk3t20+E6nC0xkiWR3NLMqrJ1zvN6l4V8hrr5sY 3d+MGZjxZuQPmWK5nrVNlmbn+4DL0/wog0x4PTvupoUVXW+2CtAfmujHOx1FQx0pskEI FcIB5WnChJ8n+e92I+Foe+bRQaNnunVPlXxftXs5StuXJYdf7eAFZUIN7nsm0R/30AEs +9gg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uAs82aUzscN4jSsQrlfhzN8+iC1+EkzFLDvHK3y5gZI=; fh=nU3AJmfDJ87vflU45x6jIlv1QGnp3PCD+htQyKOdfb8=; b=Fvnsio9iA29y57YWLpzHPtxmyOXiKrrovxpUjUEH2vdY7UoQcMBXEE+Hk2xXQbq6HP iE5waW/vH68phG8F3xJcJrzGOpaiIfFuBJ0zSiiPt+iXo5hnK4K35L0X3z3NAxS9n+8a mupd6Z6mpKwJ81vtPBfujN2BNq3C4wGl7zvJyeARxeD6ZQ4km/tTa1j7PvLq7KKDxyPv 5u7duhIoQQwceJIRkl8t4gDZsPyOPTatGZ4pOz3r6id4nl8cDNoyT/a8IfzVurN5MsOV hYytwx4CKxluzMyvjBETTDFSk5h/rBCXDgdd4OrJf+TGRfGaV9wQziPUZoa8+8FyPvr6 BCHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fcuKbjun; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id md17-20020a17090b23d100b0027408bd8420si4228994pjb.13.2023.10.13.03.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 03:20:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fcuKbjun; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 75D8A805BCB6; Fri, 13 Oct 2023 03:20:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbjJMKUG (ORCPT + 99 others); Fri, 13 Oct 2023 06:20:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjJMKUF (ORCPT ); Fri, 13 Oct 2023 06:20:05 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F22AA9; Fri, 13 Oct 2023 03:20:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAB7AC433C8; Fri, 13 Oct 2023 10:20:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697192404; bh=6ORHOHWmjImsg3NmHUcsG7SvoEhwLA+oFEammIOKG48=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fcuKbjunO2RjjyGYMrf987PGTMjKVzhwR2ORo7BIz6tYnENZqBafedukYHz3Rn27N U3cSuiB645WD2ND40VedAqDCTiXxDlCH/icjZ1ai2Q2tGqLslHgXTtb31pncWgca6/ 3svpxV1rTFrv1m1S/HC8YS86Wt6S9BSRJ2d9v1duy6ldEzAK7yEjkJrJhKY2ld616f Z6sM3H42CkiGQEI/QCJadEzuI0+F4ikGAgr+I30vo8SvOXP10mSp7zuni6dHrKqhp4 o3YFYk0fC1k9URdnME1rMK61cyqmZk1qWBdGD96YwBlKwwvKsVxU88US0tNWd4toKL W8Po2Vnk9CX8Q== Date: Fri, 13 Oct 2023 11:19:59 +0100 From: Lee Jones To: Baolin Wang Cc: Chunyan Zhang , Pavel Machek , linux-leds@vger.kernel.org, Orson Zhai , Chunyan Zhang , LKML Subject: Re: [RESEND PATCH V2] leds: sc27xx: Move mutex_init() to the end of probe Message-ID: <20231013101959.GL8314@google.com> References: <20231012034735.804157-1-chunyan.zhang@unisoc.com> <6110db84-546d-fc5c-f241-7923d673bbd5@linux.alibaba.com> <20231012091602.GD8314@google.com> <59ab760c-de22-5f62-5532-9a94427e143c@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <59ab760c-de22-5f62-5532-9a94427e143c@linux.alibaba.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 13 Oct 2023 03:20:09 -0700 (PDT) On Thu, 12 Oct 2023, Baolin Wang wrote: > > > On 10/12/2023 5:16 PM, Lee Jones wrote: > > On Thu, 12 Oct 2023, Baolin Wang wrote: > > > > > > > > > > > On 10/12/2023 11:47 AM, Chunyan Zhang wrote: > > > > Move the mutex_init() to avoid redundant mutex_destroy() calls after > > > > that for each time the probe fails. > > > > > > > > Signed-off-by: Chunyan Zhang > > > > --- > > > > Rebased onto linux-next. > > > > > > > > V2: > > > > - Move the mutex_init() to the end of .probe() instead of adding > > > > mutex_destroy() according to Lee's comments. > > > > --- > > > > drivers/leds/leds-sc27xx-bltc.c | 9 ++++----- > > > > 1 file changed, 4 insertions(+), 5 deletions(-) > > > > > > > > diff --git a/drivers/leds/leds-sc27xx-bltc.c b/drivers/leds/leds-sc27xx-bltc.c > > > > index af1f00a2f328..ef57e57ecf07 100644 > > > > --- a/drivers/leds/leds-sc27xx-bltc.c > > > > +++ b/drivers/leds/leds-sc27xx-bltc.c > > > > @@ -296,7 +296,6 @@ static int sc27xx_led_probe(struct platform_device *pdev) > > > > return -ENOMEM; > > > > platform_set_drvdata(pdev, priv); > > > > - mutex_init(&priv->lock); > > > > priv->base = base; > > > > priv->regmap = dev_get_regmap(dev->parent, NULL); > > > > if (!priv->regmap) { > > > > @@ -309,13 +308,11 @@ static int sc27xx_led_probe(struct platform_device *pdev) > > > > err = of_property_read_u32(child, "reg", ®); > > > > if (err) { > > > > of_node_put(child); > > > > - mutex_destroy(&priv->lock); > > > > return err; > > > > } > > > > if (reg >= SC27XX_LEDS_MAX || priv->leds[reg].active) { > > > > of_node_put(child); > > > > - mutex_destroy(&priv->lock); > > > > return -EINVAL; > > > > } > > > > @@ -325,9 +322,11 @@ static int sc27xx_led_probe(struct platform_device *pdev) > > > > err = sc27xx_led_register(dev, priv); > > > > if (err) > > > > - mutex_destroy(&priv->lock); > > > > + return err; > > > > - return err; > > > > + mutex_init(&priv->lock); > > > > > > I think it is better to prepare all the required resources before > > > registering the led device, what I mean is moving mutex_init() before > > > calling sc27xx_led_register(). > > > > Is the mutex used before this point? > > > > If not, I don't see any reason to initialise it sooner. > > When inserting the led module, after registering the led device, users can > set the led brightness or pattern trigger before initializing the mutex, > which will crash the system. I know this may not be an actual scenario, but > this patch opens a small race window, that's what I concerned. If there's a good technical reason to move it, then we should. -- Lee Jones [李琼斯]