From patchwork Mon Dec 3 12:19:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vaittinen, Matti" X-Patchwork-Id: 10709419 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 AB5E413BF for ; Mon, 3 Dec 2018 12:19:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B5912B4D4 for ; Mon, 3 Dec 2018 12:19:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F19E2B4DC; Mon, 3 Dec 2018 12:19:52 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 312522B4D4 for ; Mon, 3 Dec 2018 12:19:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726369AbeLCMUk (ORCPT ); Mon, 3 Dec 2018 07:20:40 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:42836 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726298AbeLCMUk (ORCPT ); Mon, 3 Dec 2018 07:20:40 -0500 Received: by mail-lf1-f66.google.com with SMTP id l10so8932731lfh.9; Mon, 03 Dec 2018 04:19:49 -0800 (PST) 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=fJ06/MEsQS8wIywHorlvQqUqrYoodnmIZrcXjxSdJq0=; b=D2BWuubqNUdvVYYA/AA48RbKlRMTG9AXZ0Mr9YGF9vcqFRLZ5w+ue9mt5wVOc9vjQI BSr2mVucz3QEDMc0EeIgHKQy2OwZBnSdV0h+jDJZ1qRp3YSTyIkUyEzV81Y7/KAAU7jz bIzWWajoCH2Gpxk8jl7yB1w6cpDt8lQaAd2DEC3zpBlYguCI6yJWjkF+mZiFapcu4NAh AKA9ioeRwQhiHfFr+KfIbdAvmyfD+DpRfngxUUYjhcLMWpRr5bJeNs1WTnoFiRAsEPwt MW2KzF80TjM+hWYdfckFu9VRmMP/9tXNG3yryqBtSNQ+V0vE+mObUY5YTXt2Nfc6v4eb PAIg== X-Gm-Message-State: AA+aEWb0N7GlQNjhFmvgohNP7jmkvtQgnEoi1V86n7VNfLTU/2tXAu3J MtQXGgybrNbFH8tFCCaulcg= X-Google-Smtp-Source: AFSGD/WgnRyEklbhrzoAdgtWZ2HOe0X9TsjA1Nq4WBaT2wWTmfqv/XbKXL3exfZ8C1DvNTpyHjbTzQ== X-Received: by 2002:a19:f510:: with SMTP id j16mr8516533lfb.35.1543839588876; Mon, 03 Dec 2018 04:19:48 -0800 (PST) Received: from localhost.localdomain ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id b21sm2309452lfi.7.2018.12.03.04.19.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Dec 2018 04:19:48 -0800 (PST) Date: Mon, 3 Dec 2018 14:19:35 +0200 From: Matti Vaittinen To: mazziesaccount@gmail.com, matti.vaittinen@fi.rohmeurope.com Cc: mturquette@baylibre.com, sboyd@kernel.org, cw00.choi@samsung.com, krzk@kernel.org, b.zolnierkie@samsung.com, linux@armlinux.org.uk, andy.gross@linaro.org, david.brown@linaro.org, pavel@ucw.cz, andrew.smirnov@gmail.com, lee.jones@linaro.org, pombredanne@nexb.com, sjhuang@iluvatar.ai, akshu.agrawal@amd.com, djkurtz@chromium.org, rafael.j.wysocki@intel.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 3/9] clk: clk-max77686: Clean clkdev lookup leak and use devm Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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 22c937644c93..e65925d5e412 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, };