Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp245574rdg; Thu, 12 Oct 2023 04:43:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYrlFcMEpErCaSwon2+vuXlL69Tq0oXRdoxxC46fpLE1iUuyPRfeDpObnqvsfO9OitIxoN X-Received: by 2002:a05:6870:4692:b0:1d1:3c89:a7e5 with SMTP id a18-20020a056870469200b001d13c89a7e5mr28090140oap.51.1697111037001; Thu, 12 Oct 2023 04:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697111036; cv=none; d=google.com; s=arc-20160816; b=KL1ZYJ4BiGsxSjqj7nzmS5nvP9gzn8PzMCCqu42axCs2DEYGPiqH9d6maQ4RI0Y+84 l11oWkpuPHMCZkyRX2YMA5KId/jXaF74W+HsWEC3H9t5bs05aCrUm0hbvaUjmYRDhRO1 AEQ19MimfJGfO8EmbfWhczlRskR++w4FiSxVbDHKtWDdSBl0OjeNEKlauHqZO7NDx/Ow Ds7LkXsbW3pxQz16DjN8a6/8XWELZhZVfeS+PYMG+4R6vu6AtdfUKikdZeo1f2qH2Zaz hba14R+tQgWjp+34LqLj6v1DtljgEXyI3TJr8HegisWh30aHp0qJNtPCzU3u/wPg3n4F qp2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=/FmhkFFSkBeElUcYgTGOoxH0C4kowB+/Djl2j22AFnY=; fh=vnUY/EuQietPbQ4MQ2BUxCWYsGiwv5SJpJYEz+LOHlg=; b=ADb7TZt+GwVDBjTSnlNJgiodwRkJ/QsOxdbEh7VCoeK3QtNzYdzhGRiG1eL/5W6PT4 J+TV+YeWLjzg/+hKoVTadftgazZ69XDLwKySBqyDSJO9dBOReJCSuoKrPWKgAM0IvRP1 +SAgXs+Tqnulbusp2MwRYy7eoz5K4H5ayGwGepuNfKXBdXz5CHn3MFzOENn7XflvqTP5 7ih4sTRWEMnKs9nYJkc0C9Mu0T+/6UjgdlcfKZ7nqEeID9Ni5TFR9WUKN2gf9+/hp5St Q8+bPkgfIdGb6aEv59mBM5vvhJ+gX4D6m6WmQqOe/pprI53XGjSBjc5kSmC3PNtJUFQt f0CQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id m8-20020a63ed48000000b005a0018ec785si2071644pgk.375.2023.10.12.04.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id BB05480310C3; Thu, 12 Oct 2023 04:43:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233709AbjJLLnr (ORCPT + 99 others); Thu, 12 Oct 2023 07:43:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232490AbjJLLnr (ORCPT ); Thu, 12 Oct 2023 07:43:47 -0400 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 558EF94; Thu, 12 Oct 2023 04:43:44 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0Vu-jJbI_1697111019; Received: from 30.97.48.41(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vu-jJbI_1697111019) by smtp.aliyun-inc.com; Thu, 12 Oct 2023 19:43:40 +0800 Message-ID: <59ab760c-de22-5f62-5532-9a94427e143c@linux.alibaba.com> Date: Thu, 12 Oct 2023 19:43:54 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [RESEND PATCH V2] leds: sc27xx: Move mutex_init() to the end of probe To: Lee Jones Cc: Chunyan Zhang , Pavel Machek , linux-leds@vger.kernel.org, Orson Zhai , Chunyan Zhang , LKML References: <20231012034735.804157-1-chunyan.zhang@unisoc.com> <6110db84-546d-fc5c-f241-7923d673bbd5@linux.alibaba.com> <20231012091602.GD8314@google.com> From: Baolin Wang In-Reply-To: <20231012091602.GD8314@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 12 Oct 2023 04:43:55 -0700 (PDT) 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.