From patchwork Fri Nov 2 12:35:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vaittinen, Matti" X-Patchwork-Id: 10665409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E03D317D5 for ; Fri, 2 Nov 2018 12:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7D232B3AF for ; Fri, 2 Nov 2018 12:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAC332B3BA; Fri, 2 Nov 2018 12:36:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6FB5A2B3AF for ; Fri, 2 Nov 2018 12:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5roY6ddPA04HjK+bqcMgpSafoJdNGOP9MmuvfTvrX+8=; b=oAgK2ovx/pyvLX Zm4LDPHWFV+s+/2oDp3qpoagAST9JlvJ0+axGQR5uxzlThtEkydvfYe9w0qEWGUADdJw9riZhwC3g u/9nkKC4N5exNjD6RSZibmPsUDDbO0i4Trj7ByiUzf2b2rlAcixTYDGh18/e7+wXVVDnWm5I3gZoq Uzi0ST/jPVyGar57J8hXSpOjlEofnPVUsvQlxprNI7/MWNgMjLsQu7PkvG6ughfMevY3AyQeZjGhv +NZgjJ+2MBtoN7WQlKtbVS6RJJ0xlOiT1yUW93Yy9hPJy+etdAsiKK9tDSp5a8bzcTcdmV9y9teDU t2iOYYgF9YORKRTQHeCQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gIYgT-0008Sq-ED; Fri, 02 Nov 2018 12:36:17 +0000 Received: from mail-lf1-f66.google.com ([209.85.167.66]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gIYgQ-0008RB-S8 for linux-arm-kernel@lists.infradead.org; Fri, 02 Nov 2018 12:36:16 +0000 Received: by mail-lf1-f66.google.com with SMTP id o2-v6so1203415lfl.13 for ; Fri, 02 Nov 2018 05:36:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Y5x+Ok5Ed4t9w7g5J7qXI1OurGBp0O2MAJGG1HebFLU=; b=oK/Fx/lVLp4L5rIw4gRyHoVunUnT5jOga5c4VgWND+/0XOi5WPRZSx1RG30QvNt15g 9AsYUy/0OhoLIu2SKHYero6H5JqoyQFQGyipZJAyjFQgvsHVpehSuS+74I2BU6nLPA1r 0mWO69+6HScF0Z5WRJEBDjGIyBMLgD1/DU6Nwh72y9AQIiY4KrONqi/3oyCXy2Dzpdco A22GUqxlf8SOE90cxdLSl+JxZAdAygsnk0mIHsBbqv7UhWwgxEr2k/UiQAdFHMUg+CUa oIgXfc+6XO1PMSFfgqNaUvoL3F8lhXFgLRz2581MoelheFQ1Ov3hcCSrO4BZynjkk1W0 KOmw== X-Gm-Message-State: AGRZ1gK4PouL7eQsOG8nKeJWM7k9Kn/fvalkF50RZsdZXveADFsQwXS+ CAy+AZ9yR4f/X7DdUBKmR94= X-Google-Smtp-Source: AJdET5dlM7Gl67fYKCTdLIuaFdbAX7CuFNVR37Z6KObOdFlosdpkknsAqp9MQje21OG0cpsW28nYRQ== X-Received: by 2002:a19:48d0:: with SMTP id v199mr6949047lfa.104.1541162163233; Fri, 02 Nov 2018 05:36:03 -0700 (PDT) Received: from localhost.localdomain ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id a63-v6sm5537119ljf.54.2018.11.02.05.36.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 02 Nov 2018 05:36:02 -0700 (PDT) Date: Fri, 2 Nov 2018 14:35:49 +0200 From: Matti Vaittinen To: Jonathan Corbet , Michael Turquette , Stephen Boyd , Chanwoo Choi , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Russell King , Andy Gross , David Brown , Kukjin Kim , Sylwester Nawrocki , Tomasz Figa , Andrey Smirnov , Sebastian Reichel , Guenter Roeck , Rob Herring , Matti Vaittinen , Huang Shijie , Akshu Agrawal , "Rafael J. Wysocki" , Daniel Kurtz , mazziesaccount@gmail.com Subject: [PATCH v3 2/7] clk: clk-max77686: Clean clkdev lookup leak and use devm Message-ID: <0be8b4ce5554e8539a458cc6152facc88a3e1804.1541161503.git.matti.vaittinen@fi.rohmeurope.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181102_053614_906172_4DFD370B X-CRM114-Status: GOOD ( 17.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-samsung-soc@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-msm@vger.kernel.org, matti.vaittinen@fi.rohmeurope.com, linux-kernel@vger.kernel.org, linux-soc@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP clk-max77686 never clean clkdev lookup at remove. This can cause oops if clk-max77686 is removed and inserted again. Fix leak by using new devm clkdev lookup registration. Simplify also error path by using new devm_of_clk_add_parent_hw_provider. Signed-off-by: Matti Vaittinen Reviewed-by: Krzysztof Kozlowski --- drivers/clk/clk-max77686.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c index 02551fe4b87c..51a46179f6f8 100644 --- a/drivers/clk/clk-max77686.c +++ b/drivers/clk/clk-max77686.c @@ -235,8 +235,9 @@ static int max77686_clk_probe(struct platform_device *pdev) return ret; } - ret = clk_hw_register_clkdev(&max_clk_data->hw, - max_clk_data->clk_idata.name, NULL); + ret = devm_clk_hw_register_clkdev(dev, &max_clk_data->hw, + max_clk_data->clk_idata.name, + NULL); if (ret < 0) { dev_err(dev, "Failed to clkdev register: %d\n", ret); return ret; @@ -244,8 +245,9 @@ static int max77686_clk_probe(struct platform_device *pdev) } if (parent->of_node) { - ret = of_clk_add_hw_provider(parent->of_node, of_clk_max77686_get, - drv_data); + ret = devm_of_clk_add_parent_hw_provider(dev, + of_clk_max77686_get, + drv_data); if (ret < 0) { dev_err(dev, "Failed to register OF clock provider: %d\n", @@ -261,27 +263,11 @@ static int max77686_clk_probe(struct platform_device *pdev) 1 << MAX77802_CLOCK_LOW_JITTER_SHIFT); if (ret < 0) { dev_err(dev, "Failed to config low-jitter: %d\n", ret); - goto remove_of_clk_provider; + return ret; } } return 0; - -remove_of_clk_provider: - if (parent->of_node) - of_clk_del_provider(parent->of_node); - - return ret; -} - -static int max77686_clk_remove(struct platform_device *pdev) -{ - struct device *parent = pdev->dev.parent; - - if (parent->of_node) - of_clk_del_provider(parent->of_node); - - return 0; } static const struct platform_device_id max77686_clk_id[] = { @@ -297,7 +283,6 @@ static struct platform_driver max77686_clk_driver = { .name = "max77686-clk", }, .probe = max77686_clk_probe, - .remove = max77686_clk_remove, .id_table = max77686_clk_id, };