From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 370C1C54791 for ; Wed, 13 Mar 2024 10:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc: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=lqDEfrqYFcVtle5JuktKuATG/akCeDYRkq1sqnZ3yos=; b=2vaZqvfr6Qo8ZZ 6tyCH1ZPlNFmK95wP2ZDffeQY218zzSRYUzOMnhhddWavYaBN1UaSkLN2V5/kcjjtdXUX3JLqLCbq 63Eyd1//YRfrGFNl97Ug0gk/k2gIISbiIoBhFfViOMHHbLqO9tjdpgki2aXW5bU3f0MO2a0fmHTPm Fw2KKSptGC9FCcrl2vxg+DjTL/2Fi4NgoLr+wTpdCXSy6b+6EP4mHU2JKXjHeoc+3Z2ucOud9XiRU RKWJquKlL4cl+47glZK6IySVfru+Xfot2Der/qv/jwwhuNwwlJP+Srxamwi5+KAaLFvcknyvuo7fM nQvQQ1hMsxLsWk4C+OUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkLXy-00000009cq2-1RRb; Wed, 13 Mar 2024 10:09:18 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkLXv-00000009cpA-37GZ for linux-arm-kernel@lists.infradead.org; Wed, 13 Mar 2024 10:09:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dqscFof3UIk2f9tQdsmkjOVmktSh5/Fa3QHjZqZqyQQ=; b=Qwx0mRY4Q4QHwU75DoBroYRY8q FFLCzsbtgdqoG2GoFm/PbyH3Aln5E+hgpBN9cgAGb39bcabXs7J5s6EMJsitA6hoHC7tC7pu1YAyB geD/7sVzA9qXD/MV3lHiHuNJVY4aa5ziK69BPhnPqfo4f6BRNe/HOKpDUrLnsKbdcGf0/tuaLXvYl vpIV/Id/Y1CHel5mzYm69GJrHkODL0iQ4URqFUWdLPWStVbIyER+OUwzBrxpsCPI+uvynp15Ogv9W at6YrOyQxED8ZiPO5pp9XZF+/QcjsI1QDPwyeUZ/Gdh8s1ApS4pEvkqnR60Y4DW+22GAoAME911Gl +Vaoi/Ow==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:33378) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rkLXn-0007X4-1k; Wed, 13 Mar 2024 10:09:07 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rkLXk-0004Pg-F8; Wed, 13 Mar 2024 10:09:04 +0000 Date: Wed, 13 Mar 2024 10:09:04 +0000 From: "Russell King (Oracle)" To: Duanqiang Wen Cc: mturquette@baylibre.com, sboyd@kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH clk] clk: clkdev: add error messages for name exceeding maximum length Message-ID: References: <20240313064252.50233-1-duanqiangwen@net-swift.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240313064252.50233-1-duanqiangwen@net-swift.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240313_030915_803659_F9304A00 X-CRM114-Status: GOOD ( 15.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Mar 13, 2024 at 02:42:52PM +0800, Duanqiang Wen wrote: > diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c > index ee37d0be6877..620dc1e80b48 100644 > --- a/drivers/clk/clkdev.c > +++ b/drivers/clk/clkdev.c > @@ -158,6 +158,9 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt, > va_list ap) > { > struct clk_lookup_alloc *cla; > + struct device *dev; > + > + dev = clk_hw_get_dev(hw); Sorry, but no, clkdev should have minimal dependencies on CCF (it was designed to be completely independent). I'd prefer not to add this. Just print the formatted dev_fmt+ap and the con_id when reporting errors. > > cla = kzalloc(sizeof(*cla), GFP_KERNEL); > if (!cla) > @@ -165,11 +168,19 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt, > > cla->cl.clk_hw = hw; > if (con_id) { > + if (strlen(dev_fmt) >= MAX_CON_ID) { This is wrong (uses dev_fmt not con_id). Also, use sizeof(cla->con_id) to test against. > + pr_err("%s:con_id string cannot be greater than 16 characters\n", dev_fmt); Cleanup? > + return NULL; > + } > strscpy(cla->con_id, con_id, sizeof(cla->con_id)); > cla->cl.con_id = cla->con_id; > } > > if (dev_fmt) { > + if (strlen(dev_fmt) >= MAX_DEV_ID) { This is also wrong. The length of the format string does not give any information on how long the resulting string actually is. > + pr_err("%s:dev_id string cannot be greater than 20 characters\n", dev_fmt); Cleanup? > + return NULL; > + } > vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap); Using vsnprintf() here and checking whether the return value is larger than sizeof(cla->dev_id) would be better. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel