Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6101637rwd; Mon, 19 Jun 2023 02:14:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Pm1wWda74r5rP6kJdx6Ca6D8r95NQWmTpVrx9x8ybTuwWYa6jAP0P0tzX/Yt8IxdumRGh X-Received: by 2002:a05:6a00:1813:b0:668:63ee:771e with SMTP id y19-20020a056a00181300b0066863ee771emr2872581pfa.15.1687166079230; Mon, 19 Jun 2023 02:14:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687166079; cv=none; d=google.com; s=arc-20160816; b=tX1rPEYSdT61HYAh8BGgUAtWNQW8e4IBrM5a6ec8gpu5f1PTVr3w9NfXx3uYMGzrn3 s7vld9Zonx/shxIfNXKjmMAPoskRkkgDQcWU68HfXrt1J73Cq2H1PiA3uHZdUC9tz8R+ 2HMgSSk9AtAbm9FD5lVkATPDbLLLO4ShsqHuoPG2Evpy3SZay8Fif9yDW1QMEWFs/q0H jcMqY8Pk/EAKMsqdoNvwrJ5JOG5NRLBPFNE1Zunp5Q6/HDhA7bYalgTFrUQTQNW3v3Xk l6KnkQ5CreDcKh+lEUJKzcuRjhqtcSZGxYCVjoxx+CyR7lxjRyQOaeRxMiEJYATSWhLt y4pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=73UFP3t8bqb8g7lRxRg12r50WZsfcyr2bTaBvl7g6DI=; b=VRcemE254FkMAJgg7usL6cqaylWuBxb/e/LzqMhrOkSyLx+Jnx1aBAIG3acDjr83Y/ mzjlVcYXvDP7WLi18KLxgCCU2fKVSRxGrImmruppwiaGQd3BGfAcjDvT739X2JOSpznB rpyJpP3EajGkTdhYDIh7TE89ySZg3VMhAj0PKStqpVo5raV0pKXJS9dykE9/nADibe5F oQvLpYaqNvgx0x5dWLycWf96t3HsPSVdblKU9CkAjEqPrJGWJQMJp6clkYVNASGV5Jxw EcTBcPqKSFFoQw1MNHZ3FhjYyDq2Y7NjEE+pcmE8YFi8XOwWPXowzuunjbSjPSmlO8YC xSbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Mn+nKD/w"; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y28-20020aa79e1c000000b0066673e30ce8si10090183pfq.272.2023.06.19.02.14.27; Mon, 19 Jun 2023 02:14:39 -0700 (PDT) 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=@chromium.org header.s=google header.b="Mn+nKD/w"; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230451AbjFSJGb (ORCPT + 99 others); Mon, 19 Jun 2023 05:06:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbjFSJG2 (ORCPT ); Mon, 19 Jun 2023 05:06:28 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EAC5102 for ; Mon, 19 Jun 2023 02:06:26 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-77e2c42de06so91829139f.1 for ; Mon, 19 Jun 2023 02:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687165585; x=1689757585; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=73UFP3t8bqb8g7lRxRg12r50WZsfcyr2bTaBvl7g6DI=; b=Mn+nKD/wyB3o0mN9yxlPrEFihNKnSHUo62EkRjzNmL3X4A8nrX3j8pirPx03mWoGVd U7Th91y2IRLJHrFAM5ocqsuO2zGew8ddd5M3x+bALzSdUju/RHJV406udcHlOSjZ5Mm+ Jtxl2QSf+7v/OL28dfLjB5KCN/m3UtFelr9+4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687165585; x=1689757585; h=content-transfer-encoding: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=73UFP3t8bqb8g7lRxRg12r50WZsfcyr2bTaBvl7g6DI=; b=NwCupoiIq4vjH1eMmcJHayJfSqAoL+37cY1GaXAnpObN1KZxNLjeiBaQUIAzs4rTQT tXVl2CxqC6+ilVifC2VICWx/hAoPMwg2K6piGEA7k/fIFS0yESWYm2E6dFyZsJqWUJle tmHF2fz6EEmR2tJrLGVcQGdK4ASuV4u7ZEQwjfrYV8dbHnSjIs3cu/LCiGbLP1YwiBWs 8AoiI8JoCFHdyC7RG4bHjGQPSG3dSCfYia/GLb0DurF9+kjP5ZilQdOP7BQu7rELLeKY 2FBHmb0omD9KK96EEO7aaRlH8FjodXe9ETP0B/odTnx2rWYlHIjp6ZnqA1j28/VbHi9E wcig== X-Gm-Message-State: AC+VfDyfuL2IczQ5je/2Lwh5qR68weVIaCOMnJ3X8wQswNtZvwKjfpKA 8ffoX0/PY6iRw1CFoQIx+2p1ZvRy4WeR8gHfcm369Q== X-Received: by 2002:a5e:8505:0:b0:77a:c494:b4bc with SMTP id i5-20020a5e8505000000b0077ac494b4bcmr6751930ioj.20.1687165585642; Mon, 19 Jun 2023 02:06:25 -0700 (PDT) Received: from mail-io1-f54.google.com (mail-io1-f54.google.com. [209.85.166.54]) by smtp.gmail.com with ESMTPSA id 16-20020a0566380a5000b0041675393f68sm4722516jap.6.2023.06.19.02.06.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Jun 2023 02:06:24 -0700 (PDT) Received: by mail-io1-f54.google.com with SMTP id ca18e2360f4ac-77e357f8faeso62237839f.3 for ; Mon, 19 Jun 2023 02:06:24 -0700 (PDT) X-Received: by 2002:a05:6602:2013:b0:763:5f1b:2f6f with SMTP id y19-20020a056602201300b007635f1b2f6fmr7963281iod.7.1687165584097; Mon, 19 Jun 2023 02:06:24 -0700 (PDT) MIME-Version: 1.0 References: <20230619112253.v2.1.I13f060c10549ef181603e921291bdea95f83033c@changeid> <35f6212e-69f8-432f-a5c8-99ed5c844f11@moroto.mountain> In-Reply-To: <35f6212e-69f8-432f-a5c8-99ed5c844f11@moroto.mountain> From: Fei Shao Date: Mon, 19 Jun 2023 17:05:47 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] clk: Fix memory leak in devm_clk_notifier_register() To: Dan Carpenter Cc: Stephen Boyd , Jerome Brunet , Michael Turquette , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Mon, Jun 19, 2023 at 4:48=E2=80=AFPM Dan Carpenter wrote: > > On Mon, Jun 19, 2023 at 11:22:53AM +0800, Fei Shao wrote: > > devm_clk_notifier_register() allocates a devres resource for clk > > notifier but didn't register that to the device, so the notifier didn't > > get unregistered on device detach and the allocated resource was leaked= . > > > > Fix the issue by registering the resource through devres_add(). > > > > Fixes: 6d30d50d037d ("clk: add devm variant of clk_notifier_register") > > Signed-off-by: Fei Shao > > --- > > > > Reviewed-by: Dan Carpenter > > How did you find this bug? > > I can think of some ways to find this bug with static analysis. > It was actually detected by kmemleak on an unreleased Chromebook device. I added the trace snippet in the message at first but removed that before sending this. Maybe I shouldn't have. I can resend a v3 to add that back if that's preferable. What do you think? Regards, Fei > KTODO: static analysis: look at unused parameters > > Both GCC and Clang have a warning for unused parameters. I think the > last time I looked at GCC it had a lot of false positives for functions > which were called as pointers but hopefully that has been fixed now? > Smatch does not have a check for this. If someone were to write it, > I would probably the check under the --pedantic flag so it would be > turned off by default. > > regards, > dan carpenter >