From patchwork Mon Mar 21 23:15:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 553392 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 363CDC4167B for ; Mon, 21 Mar 2022 23:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233314AbiCUXqx (ORCPT ); Mon, 21 Mar 2022 19:46:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233231AbiCUXqu (ORCPT ); Mon, 21 Mar 2022 19:46:50 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ED829155C; Mon, 21 Mar 2022 16:45:21 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id v22so8847821wra.2; Mon, 21 Mar 2022 16:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=uKLqUE0HqMblkYxTDEoLkraH8fYkNKsZ80vlgdu8msQ=; b=PSd5RElnYKdfT7JJ4xRmSZsf3s4ZZ2M6RghbeBlNBFjRzifBRgCWiDV7DrMIm4b7eX +s+QJOlASeV7W5CEHDrrK18BOw/rSPYOQpWO2ewmXSnwQzVb0XlkJttSS62WbzINMXjH fM2MYijB/38Dk4gB5R1MXNPmTK1c0Bg1V4ge4p1dZQtgEqQPV1BI4CicnnJfC3yJkPtZ IXQL1Mz/4H+QwCEhMSAOb2RQ3OOokFFBNsGeiOOt7Uh1lOPR5hu/V5R4pdhJHi1szrd3 hkIxMzx7ihaKt3cI6rHaVeorrGgc9w4z3sHmRS2vykSBNMoSvlq2kIut1PDcHDSjkZeX X90w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uKLqUE0HqMblkYxTDEoLkraH8fYkNKsZ80vlgdu8msQ=; b=gw1Xt8clpNeyB2ei15HtJDmI/8E8OvUjuUIVPnwc9FEL/GW0Q6smSqjzuTdtmH0bMY gJKc3YHOTKSVSGjPWXvTD45CfcE3lg1hvjGzSM/XpsUfwkPFqmzGgXBB7+uGafbFLm4S +TnhF75TRmBhVSU/u73wVeujez7CV9J4SqgpRp90gdAlV7kVJA6JJIF7hF8JXFIQ3x30 bkGKqjPsRr65NO14/NdrtcHEYs+9xuOoNURQsS1B6f69mPc2J2ja7uEfUvPJm9jSh8V9 jiPMw1gUHGrMhUX6ysYI41n3+c/M+h22LS7+8LJeRCAhE8NjuWxnWb6CaoCxmSyJ1zjl JcSQ== X-Gm-Message-State: AOAM531nGAMN+0N/D0oaBLQhuK0b71cDMoApsT9uIQNUB7Ry6PUTgF6b W0uA0pJpCgFi0BTXa1DJq7L6QrUQPz4= X-Google-Smtp-Source: ABdhPJygX3L7achtlpOONDVhOVZGbv6VOE93/ieKdwpP8aYhxet/ApXPkN9SKzQ40eRhSJNKomj63Q== X-Received: by 2002:adf:9581:0:b0:1ed:c341:4ed1 with SMTP id p1-20020adf9581000000b001edc3414ed1mr19797135wrp.299.1647906319637; Mon, 21 Mar 2022 16:45:19 -0700 (PDT) Received: from Ansuel-xps.localdomain (93-42-69-170.ip85.fastwebnet.it. [93.42.69.170]) by smtp.googlemail.com with ESMTPSA id n10-20020a5d588a000000b002052e4aaf89sm105497wrf.80.2022.03.21.16.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:45:19 -0700 (PDT) From: Ansuel Smith To: Rob Herring , Bjorn Andersson , Andy Gross , Michael Turquette , Stephen Boyd , Ansuel Smith , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org Subject: [PATCH v6 07/18] clk: qcom: clk-krait: add hw_parent check for div2_round_rate Date: Tue, 22 Mar 2022 00:15:37 +0100 Message-Id: <20220321231548.14276-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220321231548.14276-1-ansuelsmth@gmail.com> References: <20220321231548.14276-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Check if hw_parent is present before calculating the round_rate to prevent kernel panic. On error -EINVAL is reported. Signed-off-by: Ansuel Smith --- drivers/clk/qcom/clk-krait.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/clk/qcom/clk-krait.c b/drivers/clk/qcom/clk-krait.c index e447fcc3806d..b6b7650dbf15 100644 --- a/drivers/clk/qcom/clk-krait.c +++ b/drivers/clk/qcom/clk-krait.c @@ -80,7 +80,12 @@ EXPORT_SYMBOL_GPL(krait_mux_clk_ops); static long krait_div2_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) { - *parent_rate = clk_hw_round_rate(clk_hw_get_parent(hw), rate * 2); + struct clk_hw *hw_parent = clk_hw_get_parent(hw); + + if (!hw_parent) + return -EINVAL; + + *parent_rate = clk_hw_round_rate(hw_parent, rate * 2); return DIV_ROUND_UP(*parent_rate, 2); }