* [bug report] platform/mellanox: mlxreg-dpu: Add initial support for Nvidia DPU
@ 2025-05-02 8:01 Dan Carpenter
0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2025-05-02 8:01 UTC (permalink / raw)
To: Vadim Pasternak; +Cc: platform-driver-x86
Hello Vadim Pasternak,
Commit 3e75f2954116 ("platform/mellanox: mlxreg-dpu: Add initial
support for Nvidia DPU") from Apr 21, 2025 (linux-next), leads to the
following Smatch static checker warning:
drivers/platform/mellanox/mlxreg-dpu.c:539 mlxreg_dpu_probe()
warn: refcount leak 'data->hpdev.adapter->dev.kobj.kref.refcount.refs.counter': lines='539'
drivers/platform/mellanox/mlxreg-dpu.c:565 mlxreg_dpu_probe()
warn: passing a valid pointer to 'PTR_ERR'
drivers/platform/mellanox/mlxreg-dpu.c
522 static int mlxreg_dpu_probe(struct platform_device *pdev)
523 {
524 struct mlxreg_core_data *data;
525 struct mlxreg_dpu *mlxreg_dpu;
526 void *regmap;
527 int err;
528
529 data = dev_get_platdata(&pdev->dev);
530 if (!data || !data->hpdev.brdinfo)
531 return -EINVAL;
532
533 data->hpdev.adapter = i2c_get_adapter(data->hpdev.nr);
534 if (!data->hpdev.adapter)
535 return -EPROBE_DEFER;
This should call i2c_put_adapter() before returning.
536
537 mlxreg_dpu = devm_kzalloc(&pdev->dev, sizeof(*mlxreg_dpu), GFP_KERNEL);
538 if (!mlxreg_dpu)
539 return -ENOMEM;
540
541 /* Create device at the top of DPU I2C tree. */
542 data->hpdev.client = i2c_new_client_device(data->hpdev.adapter,
543 data->hpdev.brdinfo);
544 if (IS_ERR(data->hpdev.client)) {
545 dev_err(&pdev->dev, "Failed to create client %s at bus %d at addr 0x%02x\n",
546 data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr);
547 err = PTR_ERR(data->hpdev.client);
548 goto i2c_new_device_fail;
549 }
550
551 regmap = devm_regmap_init_i2c(data->hpdev.client, &mlxreg_dpu_regmap_conf);
552 if (IS_ERR(regmap)) {
553 dev_err(&pdev->dev, "Failed to create regmap for client %s at bus %d at addr 0x%02x\n",
554 data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr);
555 err = PTR_ERR(regmap);
556 goto devm_regmap_init_i2c_fail;
557 }
558
559 /* Sync registers with hardware. */
560 regcache_mark_dirty(regmap);
561 err = regcache_sync(regmap);
562 if (err) {
563 dev_err(&pdev->dev, "Failed to sync regmap for client %s at bus %d at addr 0x%02x\n",
564 data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr);
--> 565 err = PTR_ERR(regmap);
Copy and paste. "err" was already an error code. Delete this line.
566 goto regcache_sync_fail;
567 }
568
569 mlxreg_dpu->data = data;
570 mlxreg_dpu->dev = &pdev->dev;
571 platform_set_drvdata(pdev, mlxreg_dpu);
572
573 err = mlxreg_dpu_config_init(mlxreg_dpu, regmap, data, data->hpdev.brdinfo->irq);
574 if (err)
575 goto mlxreg_dpu_config_init_fail;
576
577 return err;
578
579 mlxreg_dpu_config_init_fail:
580 regcache_sync_fail:
581 devm_regmap_init_i2c_fail:
I would really encourage people to use names which reflect what
the fuction or goto does instead of where the function is called from
etc.
err_unregister:
582 i2c_unregister_device(data->hpdev.client);
583 i2c_new_device_fail:
err_i2c_put:
584 i2c_put_adapter(data->hpdev.adapter);
585 return err;
586 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-05-02 8:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-02 8:01 [bug report] platform/mellanox: mlxreg-dpu: Add initial support for Nvidia DPU Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox