Skip to content

Commit 7709fbd

Browse files
Sai Krishnadavem330
authored andcommitted
octeontx2-af: Move validation of ptp pointer before its usage
Moved PTP pointer validation before its use to avoid smatch warning. Also used kzalloc/kfree instead of devm_kzalloc/devm_kfree. Fixes: 2ef4e45 ("octeontx2-af: Add PTP PPS Errata workaround on CN10K silicon") Signed-off-by: Naveen Mamindlapalli <naveenm@marvell.com> Signed-off-by: Sunil Goutham <sgoutham@marvell.com> Signed-off-by: Sai Krishna <saikrishnag@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent af42088 commit 7709fbd

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

  • drivers/net/ethernet/marvell/octeontx2/af

drivers/net/ethernet/marvell/octeontx2/af/ptp.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ struct ptp *ptp_get(void)
208208
/* Check driver is bound to PTP block */
209209
if (!ptp)
210210
ptp = ERR_PTR(-EPROBE_DEFER);
211-
else
211+
else if (!IS_ERR(ptp))
212212
pci_dev_get(ptp->pdev);
213213

214214
return ptp;
@@ -388,11 +388,10 @@ static int ptp_extts_on(struct ptp *ptp, int on)
388388
static int ptp_probe(struct pci_dev *pdev,
389389
const struct pci_device_id *ent)
390390
{
391-
struct device *dev = &pdev->dev;
392391
struct ptp *ptp;
393392
int err;
394393

395-
ptp = devm_kzalloc(dev, sizeof(*ptp), GFP_KERNEL);
394+
ptp = kzalloc(sizeof(*ptp), GFP_KERNEL);
396395
if (!ptp) {
397396
err = -ENOMEM;
398397
goto error;
@@ -428,37 +427,37 @@ static int ptp_probe(struct pci_dev *pdev,
428427
return 0;
429428

430429
error_free:
431-
devm_kfree(dev, ptp);
430+
kfree(ptp);
432431

433432
error:
434433
/* For `ptp_get()` we need to differentiate between the case
435434
* when the core has not tried to probe this device and the case when
436-
* the probe failed. In the later case we pretend that the
437-
* initialization was successful and keep the error in
435+
* the probe failed. In the later case we keep the error in
438436
* `dev->driver_data`.
439437
*/
440438
pci_set_drvdata(pdev, ERR_PTR(err));
441439
if (!first_ptp_block)
442440
first_ptp_block = ERR_PTR(err);
443441

444-
return 0;
442+
return err;
445443
}
446444

447445
static void ptp_remove(struct pci_dev *pdev)
448446
{
449447
struct ptp *ptp = pci_get_drvdata(pdev);
450448
u64 clock_cfg;
451449

452-
if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
453-
hrtimer_cancel(&ptp->hrtimer);
454-
455450
if (IS_ERR_OR_NULL(ptp))
456451
return;
457452

453+
if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
454+
hrtimer_cancel(&ptp->hrtimer);
455+
458456
/* Disable PTP clock */
459457
clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG);
460458
clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN;
461459
writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG);
460+
kfree(ptp);
462461
}
463462

464463
static const struct pci_device_id ptp_id_table[] = {

drivers/net/ethernet/marvell/octeontx2/af/rvu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3252,7 +3252,7 @@ static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id)
32523252
rvu->ptp = ptp_get();
32533253
if (IS_ERR(rvu->ptp)) {
32543254
err = PTR_ERR(rvu->ptp);
3255-
if (err == -EPROBE_DEFER)
3255+
if (err)
32563256
goto err_release_regions;
32573257
rvu->ptp = NULL;
32583258
}

0 commit comments

Comments
 (0)