public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: jacopo.mondi@ideasonboard.com
Cc: linux-media@vger.kernel.org
Subject: [bug report] media: i2c: ov5670: Use common clock framework
Date: Wed, 8 Feb 2023 16:37:35 +0300	[thread overview]
Message-ID: <Y+Oln/uxPVwKVwFX@kili> (raw)

Hello Jacopo Mondi,

The patch 8004c91e2095: "media: i2c: ov5670: Use common clock
framework" from Jan 26, 2023, leads to the following Smatch static
checker warning:

	drivers/media/i2c/ov5670.c:2670 ov5670_probe()
	warn: passing zero to 'PTR_ERR'

drivers/media/i2c/ov5670.c
    2648 static int ov5670_probe(struct i2c_client *client)
    2649 {
    2650         struct ov5670 *ov5670;
    2651         const char *err_msg;
    2652         u32 input_clk = 0;
    2653         bool full_power;
    2654         int ret;
    2655 
    2656         ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL);
    2657         if (!ov5670) {
    2658                 ret = -ENOMEM;
    2659                 err_msg = "devm_kzalloc() error";
    2660                 goto error_print;
    2661         }
    2662 
    2663         ov5670->xvclk = devm_clk_get(&client->dev, NULL);
    2664         if (!IS_ERR_OR_NULL(ov5670->xvclk))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Imagine CONFIG_HAVE_CLK is not enabled so now devm_clk_get() returns
NULL. 

    2665                 input_clk = clk_get_rate(ov5670->xvclk);
    2666         else if (PTR_ERR(ov5670->xvclk) == -ENOENT)
    2667                 device_property_read_u32(&client->dev, "clock-frequency",
    2668                                          &input_clk);
    2669         else
--> 2670                 return dev_err_probe(&client->dev, PTR_ERR(ov5670->xvclk),
    2671                                      "error getting clock\n");

A NULL is zero and zero is success.

That means this code returns success without doing anything.  Perhaps
the right thing is to use use Kconfig to ensure that this cannot be
build without CONFIG_HAVE_CLK.  The other solution is to write the
driver with a bunch of NULL checks so that it still runs without a clk.

The IS_ERR_OR_NULL() check should be changed to if (IS_ERR()).

    2672 
    2673         if (input_clk != OV5670_XVCLK_FREQ) {
    2674                 dev_err(&client->dev,
    2675                         "Unsupported clock frequency %u\n", input_clk);
    2676                 return -EINVAL;
    2677         }
    2678 
    2679         /* Initialize subdev */
    2680         v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops);
    2681 
    2682         ret = ov5670_regulators_probe(ov5670);
    2683         if (ret) {
    2684                 err_msg = "Regulators probe failed";

regards,
dan carpenter

             reply	other threads:[~2023-02-08 13:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 13:37 Dan Carpenter [this message]
2023-02-08 14:23 ` [bug report] media: i2c: ov5670: Use common clock framework Jacopo Mondi
2023-02-08 14:30   ` Jacopo Mondi
2023-02-08 15:02   ` Dan Carpenter
2023-02-08 15:47     ` Jacopo Mondi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y+Oln/uxPVwKVwFX@kili \
    --to=error27@gmail.com \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox