From patchwork Tue Apr 6 23:06:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 415944 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp4989155jai; Tue, 6 Apr 2021 16:06:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJxj/FEq0ZQt4wW3dwei1bOHfv8Y4arTSOy/bBaTYQ+O1ipOOt5gU5LecS3I9n2ABUaPDQ X-Received: by 2002:a63:d70e:: with SMTP id d14mr436803pgg.291.1617750374738; Tue, 06 Apr 2021 16:06:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617750374; cv=none; d=google.com; s=arc-20160816; b=Z9vKBNNDW/dB7zAbjGT5C1qlth7kOF9ox2nyCwZXnhV+GtqNk5rBaomJYzb42uDcbr qcN89WlojbMzwD2nTTJ11MXKMSdqWd9aBpR0eVtLaRgA7bA9zpb4MYFYEEqI5+3cvwOB sz61IMj6ARKhAnvxDzTwoOEm7rG9FZWa4lqzJrQI+Bny7m+aTWHCntTOz6KppYwWT0QI FHcVhKr2tNvVe8l+oitffswfgdXRczmAu0eoVKvOhbNvrSbXlStaTi4masqlNP0HLErp ccFwo1CRIvS2/TjX9PdKIDNG4H1n/EjzxVk9sZ4T9GUe59eRxPlRCRgIO4ZirvIdlnbB CVqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :dkim-signature:delivered-to; bh=yWosVfWGH4CgGi+Lndw+41Oo/T0rpNuP6x5CwVx48sM=; b=ZV6n30+V+qNrfRsBeypylG9o6ObL7rwU4zLY3X722QE+pQDrwH5dUZsTtb6NG1D9tP 33zk9HdlqQYO4KU/NqCcDuB4fgpZwNkaw32Uf46F1KcudEfHmDjsHGOIxkDl2JxJTf26 4pktEkjJZLpgCI5Qze+FgMDY3jwbyVisP5YD1fohzniwd4Tkjd33PNAPMO3hOXEnI+A0 rhEhjoDlyhm1PT5B4u+eLBaXv9wPUw2ufLLGJ/6sYYuCBDRIcTkBB49qSRYzmR5xmlFf YyR9MAEQ8yOEwIsD2mT5cD/7811WYrVgjhV11B1qCynxk0vMSdrQgzqI/bBaFDAfr8qL YrFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TpblUsbt; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id t21si17164541pfh.59.2021.04.06.16.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 16:06:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TpblUsbt; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 36A0D89FEA; Tue, 6 Apr 2021 23:06:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6333E89FEA for ; Tue, 6 Apr 2021 23:06:09 +0000 (UTC) Received: by mail-lj1-x229.google.com with SMTP id y1so18360216ljm.10 for ; Tue, 06 Apr 2021 16:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aPWXCRyQycYQvj6HYAPrgu+5Z9a57EfhLN3d1yHm7Ps=; b=TpblUsbtD5po/N9CH/uKdwv0vEB3mnX65H7KPdYRddC7mVJFSjpYcspElVN2O/5zzv 2NpmbX9x1UTxC/AiZlaBMKn4eS9jCVyuZQ/exmSW+stHaDAlpm6HzEuLtv+YbAGyjeua V4S8RLiqJk+mcEOvLgVUqhmmcWK2LLUItP/tmnl5KhP45rkzszvaaqhxln/vB2NErNSF whPy8AlWU59tdX6njnk0uAnKlCsN7wG36UGU6SFGzJ3mGEaoee9u6DAarPFvGZCBgvJN qqevv4fjV00ioLnCri+pzlI9ZIilUwxBMtOxAcgry/cd3REqfT8EOVLrcqTJqQiyak+f oa4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aPWXCRyQycYQvj6HYAPrgu+5Z9a57EfhLN3d1yHm7Ps=; b=V4IP0oP7a3crGJDu7IcVJcp94aKPLHLtexJlYeX4nDGxFhp5HS0zqFar8jQ9oGm/ks bYIoXWKZCC8qnF1Cw2MsPjgE43lLKWeGMjU8gp6L8STYe97+5vSLA7YNEjZ9lOXvG/Kh HN1LJiVLsLWBt5wAYnV5Bjsesx50XgSTI+LuRRRLai7JWwBbMb+0VsdANsnrj17lFFVr ibJoRmqhUH8SelHvr5Fa68YPvkhix4oPG0EW5LyU+G51VjEM8MW/lrO5kzqc9b2TnsJo 8h70h9f+7dEBXCbl2W/Tncq1+MEwqy6zhrNqRHxX2LFoovrLhXd7RrD+kXaLOAc8n51+ u2Yg== X-Gm-Message-State: AOAM532cRNfHj7iVL9L9ctLNFdIzZU/on+cJn9qhaHamkPjEbIgVMBq2 m+zenkZJuxc2yuSpFMmnV56/Ig== X-Received: by 2002:a05:651c:ca:: with SMTP id 10mr240945ljr.63.1617750367763; Tue, 06 Apr 2021 16:06:07 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id b25sm2351498ljo.80.2021.04.06.16.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 16:06:07 -0700 (PDT) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , Stephen Boyd , Michael Turquette Subject: [PATCH] clk: fixed: fix double free in resource managed fixed-factor clock Date: Wed, 7 Apr 2021 02:06:06 +0300 Message-Id: <20210406230606.3007138-1-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , linux-arm-msm@vger.kernel.org, Daniel Palmer , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-clk@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" devm_clk_hw_register_fixed_factor_release(), the release function for the devm_clk_hw_register_fixed_factor(), calls clk_hw_unregister_fixed_factor(), which will kfree() the clock. However after that the devres functions will also kfree the allocated data, resulting in double free/memory corruption. Just call clk_hw_unregister() instead, leaving kfree() to devres code. Reported-by: Rob Clark Cc: Daniel Palmer Signed-off-by: Dmitry Baryshkov --- Stephen, this fix affects the DSI PHY rework. Do we have a chance of getting it into 5.12, otherwise there will be a cross-dependency between msm-next and clk-next. --- drivers/clk/clk-fixed-factor.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) -- 2.30.2 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c index 4f7bf3929d6d..390c16f321a6 100644 --- a/drivers/clk/clk-fixed-factor.c +++ b/drivers/clk/clk-fixed-factor.c @@ -66,7 +66,12 @@ EXPORT_SYMBOL_GPL(clk_fixed_factor_ops); static void devm_clk_hw_register_fixed_factor_release(struct device *dev, void *res) { - clk_hw_unregister_fixed_factor(&((struct clk_fixed_factor *)res)->hw); + /* + * We can not use clk_hw_unregister_fixed_factor, since it will kfree() + * the hw, resulting in double free. Just unregister the hw and let + * devres code kfree() it. + */ + clk_hw_unregister(&((struct clk_fixed_factor *)res)->hw); } static struct clk_hw *