Re: [PATCH v6 3/4] clk: sophgo: Add SG2042 clock generator driver

From: Chen Wang
Date: Mon Dec 11 2023 - 19:06:07 EST



On 2023/12/9 14:22, Dan Carpenter wrote:
Hi Chen,

kernel test robot noticed the following build warnings:

url: https://github.com/intel-lab-lkp/linux/commits/Chen-Wang/dt-bindings-soc-sophgo-Add-Sophgo-system-control-module/20231208-091702
base: b85ea95d086471afb4ad062012a4d73cd328fa86
patch link: https://lore.kernel.org/r/d1aa4f76f360ebd7b790a4786641f1b0188dbba8.1701997033.git.unicorn_wang%40outlook.com
patch subject: [PATCH v6 3/4] clk: sophgo: Add SG2042 clock generator driver
config: xtensa-randconfig-r071-20231208 (https://download.01.org/0day-ci/archive/20231208/202312081933.MUdHNASt-lkp@xxxxxxxxx/config)
compiler: xtensa-linux-gcc (GCC) 13.2.0
reproduce: (https://download.01.org/0day-ci/archive/20231208/202312081933.MUdHNASt-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
| Closes: https://lore.kernel.org/r/202312081933.MUdHNASt-lkp@xxxxxxxxx/

smatch warnings:
drivers/clk/sophgo/clk-sophgo-sg2042.c:1282 sg2042_clk_init_clk_data() warn: passing zero to 'PTR_ERR'
Thank you, Dan. I will try to remove this warning in next revision.

vim +/PTR_ERR +1282 drivers/clk/sophgo/clk-sophgo-sg2042.c

7c68ebea1041f9 Chen Wang 2023-12-08 1258 static int __init sg2042_clk_init_clk_data(
7c68ebea1041f9 Chen Wang 2023-12-08 1259 struct device_node *node,
7c68ebea1041f9 Chen Wang 2023-12-08 1260 int num_clks,
7c68ebea1041f9 Chen Wang 2023-12-08 1261 struct sg2042_clk_data **pp_clk_data)
7c68ebea1041f9 Chen Wang 2023-12-08 1262 {
7c68ebea1041f9 Chen Wang 2023-12-08 1263 int ret = 0;
7c68ebea1041f9 Chen Wang 2023-12-08 1264 struct sg2042_clk_data *clk_data = NULL;
7c68ebea1041f9 Chen Wang 2023-12-08 1265 struct device_node *np_syscon;
7c68ebea1041f9 Chen Wang 2023-12-08 1266
7c68ebea1041f9 Chen Wang 2023-12-08 1267 np_syscon = of_parse_phandle(node, "sophgo,system-ctrl", 0);
7c68ebea1041f9 Chen Wang 2023-12-08 1268 if (!np_syscon) {
7c68ebea1041f9 Chen Wang 2023-12-08 1269 pr_err("failed to get system-ctrl node\n");
7c68ebea1041f9 Chen Wang 2023-12-08 1270 ret = -EINVAL;
7c68ebea1041f9 Chen Wang 2023-12-08 1271 goto error_out;
7c68ebea1041f9 Chen Wang 2023-12-08 1272 }
7c68ebea1041f9 Chen Wang 2023-12-08 1273
7c68ebea1041f9 Chen Wang 2023-12-08 1274 clk_data = kzalloc(struct_size(clk_data, onecell_data.hws, num_clks), GFP_KERNEL);
7c68ebea1041f9 Chen Wang 2023-12-08 1275 if (!clk_data) {
7c68ebea1041f9 Chen Wang 2023-12-08 1276 ret = -ENOMEM;
7c68ebea1041f9 Chen Wang 2023-12-08 1277 goto error_out;
7c68ebea1041f9 Chen Wang 2023-12-08 1278 }
7c68ebea1041f9 Chen Wang 2023-12-08 1279
7c68ebea1041f9 Chen Wang 2023-12-08 1280 clk_data->regmap_syscon = device_node_to_regmap(np_syscon);
7c68ebea1041f9 Chen Wang 2023-12-08 1281 if (IS_ERR_OR_NULL(clk_data->regmap_syscon)) {
7c68ebea1041f9 Chen Wang 2023-12-08 @1282 pr_err("cannot get regmap_syscon %ld\n", PTR_ERR(clk_data->regmap_syscon));

I don't think device_node_to_regmap() can return NULL, but if it could
then it shouldn't be handled like this:

https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/


7c68ebea1041f9 Chen Wang 2023-12-08 1283 ret = -ENODEV;
7c68ebea1041f9 Chen Wang 2023-12-08 1284 goto cleanup;
7c68ebea1041f9 Chen Wang 2023-12-08 1285 }
7c68ebea1041f9 Chen Wang 2023-12-08 1286 clk_data->iobase_syscon = of_iomap(np_syscon, 0);
7c68ebea1041f9 Chen Wang 2023-12-08 1287 clk_data->iobase = of_iomap(node, 0);
7c68ebea1041f9 Chen Wang 2023-12-08 1288 clk_data->onecell_data.num = num_clks;
7c68ebea1041f9 Chen Wang 2023-12-08 1289
7c68ebea1041f9 Chen Wang 2023-12-08 1290 *pp_clk_data = clk_data;
7c68ebea1041f9 Chen Wang 2023-12-08 1291 return ret;
7c68ebea1041f9 Chen Wang 2023-12-08 1292
7c68ebea1041f9 Chen Wang 2023-12-08 1293 cleanup:
7c68ebea1041f9 Chen Wang 2023-12-08 1294 kfree(clk_data);
7c68ebea1041f9 Chen Wang 2023-12-08 1295
7c68ebea1041f9 Chen Wang 2023-12-08 1296 error_out:
7c68ebea1041f9 Chen Wang 2023-12-08 1297 return ret;
7c68ebea1041f9 Chen Wang 2023-12-08 1298 }