From patchwork Thu Feb 9 20:12:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 652239 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 12CF8C636D6 for ; Thu, 9 Feb 2023 20:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229658AbjBIUM5 (ORCPT ); Thu, 9 Feb 2023 15:12:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbjBIUM4 (ORCPT ); Thu, 9 Feb 2023 15:12:56 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BD5B2D171 for ; Thu, 9 Feb 2023 12:12:55 -0800 (PST) Received: from uno.localdomain (mob-176-242-40-117.net.vodafone.it [176.242.40.117]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A772A9CA; Thu, 9 Feb 2023 21:12:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1675973573; bh=XNJy0Z0MmhZs7tePJiQexWJ3ea9DjdTZ9ihszHxrTTI=; h=From:To:Cc:Subject:Date:From; b=dpCeUEpGWmmkmSbsrX4JxUvVU4VH2PTcxiaIS1TyzcebJvcTd8Hsqtu/3Vp8vmmEt YUH4FBu6qk2vL+uIhIz3Gh85tt7tlPpjKAIIyNm5bVZ9ixmi9s2QAvxErMauaJ+LoH 1u7ADkNhTcYMNFeS5KoKKVfXFJfLMC3/TWpxwbaA= From: Jacopo Mondi To: mchehab@kernel.org, sakari.ailus@linux.intel.com, Dan Carpenter Cc: Jacopo Mondi , linux-media@vger.kernel.org Subject: [PATCH] media: i2c: ov5670: Properly handle !CONFIG_HAVE_CLK Date: Thu, 9 Feb 2023 21:12:35 +0100 Message-Id: <20230209201235.206188-1-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The ov5670 driver tries to get a reference to the xvclk provider by using the common cock framework and deflects to parsing the "clock-frequency" property in case the clock provider is not specified in the firmware interface, detected by checking if ov5670->xvclk == PTR_ERR(-ENOENT). However, as reported by the Smatch static checker, if CONFIG_HAVE_CLK is not enabled, devm_clk_get() returns 0 which when passed to PTR_ERR() means success causing the driver to fail without propagating any error code up. Explicitly handle the case where ov5670->xvclk it set to NULL, forcing the code to parse the "clock-frequency" property in case CONFIG_HAVE_CLK is not enabled, as suggested by Dan Carpenter. Reported-by: Dan Carpenter Suggested-by: Dan Carpenter Signed-off-by: Jacopo Mondi --- Patch based on Sakari's master branch. As the patch series has not landed in Mauro's tree, I've not added a Fixes: tag yet. --- drivers/media/i2c/ov5670.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.39.0 diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index f79d908f4531..275ae24316fe 100644 --- a/drivers/media/i2c/ov5670.c +++ b/drivers/media/i2c/ov5670.c @@ -2663,7 +2663,7 @@ static int ov5670_probe(struct i2c_client *client) ov5670->xvclk = devm_clk_get(&client->dev, NULL); if (!IS_ERR_OR_NULL(ov5670->xvclk)) input_clk = clk_get_rate(ov5670->xvclk); - else if (PTR_ERR(ov5670->xvclk) == -ENOENT) + else if (!ov5670->xvclk || PTR_ERR(ov5670->xvclk) == -ENOENT) device_property_read_u32(&client->dev, "clock-frequency", &input_clk); else