Skip to content

Commit

Permalink
ptp: vmclock: Remove goto-based cleanup logic
Browse files Browse the repository at this point in the history
vmclock_probe() uses an "out:" label to return from the function on
error. This indicates that some cleanup operation is necessary.
However the label does not do anything as all resources are managed
through devres, making the code slightly harder to read.

Remove the label and just return directly.

Signed-off-by: Thomas Weißschuh <[email protected]>
Acked-by: Richard Cochran <[email protected]>
Reviewed-by: David Woodhouse <[email protected]>
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
t-8ch authored and Paolo Abeni committed Feb 11, 2025
1 parent 9a884c3 commit b4c1fde
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions drivers/ptp/ptp_vmclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,52 +506,48 @@ static int vmclock_probe(struct platform_device *pdev)

if (ret) {
dev_info(dev, "Failed to obtain physical address: %d\n", ret);
goto out;
return ret;
}

if (resource_size(&st->res) < VMCLOCK_MIN_SIZE) {
dev_info(dev, "Region too small (0x%llx)\n",
resource_size(&st->res));
ret = -EINVAL;
goto out;
return -EINVAL;
}
st->clk = devm_memremap(dev, st->res.start, resource_size(&st->res),
MEMREMAP_WB | MEMREMAP_DEC);
if (IS_ERR(st->clk)) {
ret = PTR_ERR(st->clk);
dev_info(dev, "failed to map shared memory\n");
st->clk = NULL;
goto out;
return ret;
}

if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC ||
le32_to_cpu(st->clk->size) > resource_size(&st->res) ||
le16_to_cpu(st->clk->version) != 1) {
dev_info(dev, "vmclock magic fields invalid\n");
ret = -EINVAL;
goto out;
return -EINVAL;
}

ret = ida_alloc(&vmclock_ida, GFP_KERNEL);
if (ret < 0)
goto out;
return ret;

st->index = ret;
ret = devm_add_action_or_reset(&pdev->dev, vmclock_put_idx, st);
if (ret)
goto out;
return ret;

st->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "vmclock%d", st->index);
if (!st->name) {
ret = -ENOMEM;
goto out;
}
if (!st->name)
return -ENOMEM;

st->miscdev.minor = MISC_DYNAMIC_MINOR;

ret = devm_add_action_or_reset(&pdev->dev, vmclock_remove, st);
if (ret)
goto out;
return ret;

/*
* If the structure is big enough, it can be mapped to userspace.
Expand All @@ -565,7 +561,7 @@ static int vmclock_probe(struct platform_device *pdev)

ret = misc_register(&st->miscdev);
if (ret)
goto out;
return ret;
}

/* If there is valid clock information, register a PTP clock */
Expand All @@ -575,24 +571,22 @@ static int vmclock_probe(struct platform_device *pdev)
if (IS_ERR(st->ptp_clock)) {
ret = PTR_ERR(st->ptp_clock);
st->ptp_clock = NULL;
goto out;
return ret;
}
}

if (!st->miscdev.minor && !st->ptp_clock) {
/* Neither miscdev nor PTP registered */
dev_info(dev, "vmclock: Neither miscdev nor PTP available; not registering\n");
ret = -ENODEV;
goto out;
return -ENODEV;
}

dev_info(dev, "%s: registered %s%s%s\n", st->name,
st->miscdev.minor ? "miscdev" : "",
(st->miscdev.minor && st->ptp_clock) ? ", " : "",
st->ptp_clock ? "PTP" : "");

out:
return ret;
return 0;
}

static const struct acpi_device_id vmclock_acpi_ids[] = {
Expand Down

0 comments on commit b4c1fde

Please sign in to comment.