Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp850480pxb; Wed, 6 Apr 2022 01:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8sURcYE75apNkAxxbs5zwAvbhe9OBcJ2gBBY+f3OaTyk9jof52OC6sx77TbpuP37QEvLB X-Received: by 2002:a17:90a:b10c:b0:1ca:ba2d:d67d with SMTP id z12-20020a17090ab10c00b001caba2dd67dmr8777592pjq.127.1649235306724; Wed, 06 Apr 2022 01:55:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649235306; cv=none; d=google.com; s=arc-20160816; b=Ysu465wfm5GCQ5FcTmPo3ID00Vr6xEq/ludZjSS+hbj5KRlDpfciEyBkjDBWg1zuV7 bPnwDG3zdV4b2YDO8HcBlLhopZ5Rn8LeYPaFBuBmiBQLZwbqAE+woBzhoVv4P3aOb3bK Z2pSefOgtd8RsnxiNGLJpob3RKCMhS9HfHvpfRHzUHlJiQ1VJ0KwFcl642t7urXCAQbw TqHLa0K7m0EolexS6Nm1VzJH1dvStgEuCG5BsfhP1XjeptQMTvIGf8nue5bSodlAqc7T QhEA3Xb3yU45qP0zDFhrxFE5Vs7mzyjoRKFi/+2JAetdoAR3ET6QMpD8blHbmiRMYk9V 3Rsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FPwGnBlnjOW/XNhzlXB5b6n0ZyRh0WSe9B2ZbJ1Y/WU=; b=iPmDDnNzcOqxqUHSVCaV/GLG9Ad92Kh8k6GADsS6U2FsfT5ciZGt3vyLLBDMurSZGS 41GcNI4hEsGzC3DQ/l4Nflb1RluYpOVF60Rgz1OOyo+iB1wMXPQRYfPbjGHeuE9KbBrY z/eUHk+hS+TsClrcvdHyXNgMt3YIkdmiyvVtrQsRzNYFIKuatVkOobN6jPIaHgAnVz+R jRVJyuKIoxludJ36+qJEhoPUvwttKV0N74Oqhq53OtUhFia7oHD8n3UW9qVt6jFL7x+X x2/w60cW5o5Q2m5IjLvloF4T7QIA/3HWWUPotlAJwQ/7dn7s3KVCjzXfwt9TIb0P9VI0 Awww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C3lnjFks; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s4-20020a632144000000b003816043f12fsi15302271pgm.804.2022.04.06.01.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 01:55:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C3lnjFks; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 92F5058954F; Wed, 6 Apr 2022 01:47:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348034AbiDEJ3G (ORCPT + 99 others); Tue, 5 Apr 2022 05:29:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239532AbiDEIUN (ORCPT ); Tue, 5 Apr 2022 04:20:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F259AF6B; Tue, 5 Apr 2022 01:15:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9F3D8B81BB1; Tue, 5 Apr 2022 08:15:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBDC2C385A1; Tue, 5 Apr 2022 08:15:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146531; bh=di7Ywnyc7PQuSoaczewXq/7OS/GDikrcKHmRBrlnno4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C3lnjFksrur3sCjth4vC8I5oTliF+Bg3v/0oS7TMbwofHZraCQS8ZZEjk3gTxA1BX tmnY//frA9+TjY76Y/YWV9PadIFijgmY8iqWOk4HlxeW4rrRNILKpZoLK6IXcdxQ9S PegI7/eD0BLMoHB53RkjHbNCQx1CYrEPKCoNRb7c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxime Ripard , Stephen Boyd , Sasha Levin Subject: [PATCH 5.17 0759/1126] clk: Fix clk_hw_get_clk() when dev is NULL Date: Tue, 5 Apr 2022 09:25:06 +0200 Message-Id: <20220405070429.861668196@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Maxime Ripard [ Upstream commit 0c1b56df451716ba207bbf59f303473643eee4fd ] Any registered clk_core structure can have a NULL pointer in its dev field. While never actually documented, this is evidenced by the wide usage of clk_register and clk_hw_register with a NULL device pointer, and the fact that the core of_clk_hw_register() function also passes a NULL device pointer. A call to clk_hw_get_clk() on a clk_hw struct whose clk_core is in that case will result in a NULL pointer derefence when it calls dev_name() on that NULL device pointer. Add a test for this case and use NULL as the dev_id if the device pointer is NULL. Fixes: 30d6f8c15d2c ("clk: add api to get clk consumer from clk_hw") Signed-off-by: Maxime Ripard Link: https://lore.kernel.org/r/20220225143534.405820-2-maxime@cerno.tech Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/clk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 8de6a22498e7..fff5edb89d6d 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3773,8 +3773,9 @@ struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id) { struct device *dev = hw->core->dev; + const char *name = dev ? dev_name(dev) : NULL; - return clk_hw_create_clk(dev, hw, dev_name(dev), con_id); + return clk_hw_create_clk(dev, hw, name, con_id); } EXPORT_SYMBOL(clk_hw_get_clk); -- 2.34.1