octeontx2-af: Move validation of ptp pointer before its usage
[ Upstream commit 7709fbd4922c197efabda03660d93e48a3e80323 ]
Moved PTP pointer validation before its use to avoid smatch warning.
Also used kzalloc/kfree instead of devm_kzalloc/devm_kfree.
Fixes: 2ef4e45d99 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
bb56b7905b
commit
6cc293d29c
2 changed files with 10 additions and 11 deletions
|
|
@ -208,7 +208,7 @@ struct ptp *ptp_get(void)
|
||||||
/* Check driver is bound to PTP block */
|
/* Check driver is bound to PTP block */
|
||||||
if (!ptp)
|
if (!ptp)
|
||||||
ptp = ERR_PTR(-EPROBE_DEFER);
|
ptp = ERR_PTR(-EPROBE_DEFER);
|
||||||
else
|
else if (!IS_ERR(ptp))
|
||||||
pci_dev_get(ptp->pdev);
|
pci_dev_get(ptp->pdev);
|
||||||
|
|
||||||
return ptp;
|
return ptp;
|
||||||
|
|
@ -388,11 +388,10 @@ static int ptp_extts_on(struct ptp *ptp, int on)
|
||||||
static int ptp_probe(struct pci_dev *pdev,
|
static int ptp_probe(struct pci_dev *pdev,
|
||||||
const struct pci_device_id *ent)
|
const struct pci_device_id *ent)
|
||||||
{
|
{
|
||||||
struct device *dev = &pdev->dev;
|
|
||||||
struct ptp *ptp;
|
struct ptp *ptp;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
ptp = devm_kzalloc(dev, sizeof(*ptp), GFP_KERNEL);
|
ptp = kzalloc(sizeof(*ptp), GFP_KERNEL);
|
||||||
if (!ptp) {
|
if (!ptp) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto error;
|
goto error;
|
||||||
|
|
@ -428,20 +427,19 @@ static int ptp_probe(struct pci_dev *pdev,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_free:
|
error_free:
|
||||||
devm_kfree(dev, ptp);
|
kfree(ptp);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
/* For `ptp_get()` we need to differentiate between the case
|
/* For `ptp_get()` we need to differentiate between the case
|
||||||
* when the core has not tried to probe this device and the case when
|
* when the core has not tried to probe this device and the case when
|
||||||
* the probe failed. In the later case we pretend that the
|
* the probe failed. In the later case we keep the error in
|
||||||
* initialization was successful and keep the error in
|
|
||||||
* `dev->driver_data`.
|
* `dev->driver_data`.
|
||||||
*/
|
*/
|
||||||
pci_set_drvdata(pdev, ERR_PTR(err));
|
pci_set_drvdata(pdev, ERR_PTR(err));
|
||||||
if (!first_ptp_block)
|
if (!first_ptp_block)
|
||||||
first_ptp_block = ERR_PTR(err);
|
first_ptp_block = ERR_PTR(err);
|
||||||
|
|
||||||
return 0;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ptp_remove(struct pci_dev *pdev)
|
static void ptp_remove(struct pci_dev *pdev)
|
||||||
|
|
@ -449,16 +447,17 @@ static void ptp_remove(struct pci_dev *pdev)
|
||||||
struct ptp *ptp = pci_get_drvdata(pdev);
|
struct ptp *ptp = pci_get_drvdata(pdev);
|
||||||
u64 clock_cfg;
|
u64 clock_cfg;
|
||||||
|
|
||||||
if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
|
|
||||||
hrtimer_cancel(&ptp->hrtimer);
|
|
||||||
|
|
||||||
if (IS_ERR_OR_NULL(ptp))
|
if (IS_ERR_OR_NULL(ptp))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (cn10k_ptp_errata(ptp) && hrtimer_active(&ptp->hrtimer))
|
||||||
|
hrtimer_cancel(&ptp->hrtimer);
|
||||||
|
|
||||||
/* Disable PTP clock */
|
/* Disable PTP clock */
|
||||||
clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG);
|
clock_cfg = readq(ptp->reg_base + PTP_CLOCK_CFG);
|
||||||
clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN;
|
clock_cfg &= ~PTP_CLOCK_CFG_PTP_EN;
|
||||||
writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG);
|
writeq(clock_cfg, ptp->reg_base + PTP_CLOCK_CFG);
|
||||||
|
kfree(ptp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct pci_device_id ptp_id_table[] = {
|
static const struct pci_device_id ptp_id_table[] = {
|
||||||
|
|
|
||||||
|
|
@ -3244,7 +3244,7 @@ static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
||||||
rvu->ptp = ptp_get();
|
rvu->ptp = ptp_get();
|
||||||
if (IS_ERR(rvu->ptp)) {
|
if (IS_ERR(rvu->ptp)) {
|
||||||
err = PTR_ERR(rvu->ptp);
|
err = PTR_ERR(rvu->ptp);
|
||||||
if (err == -EPROBE_DEFER)
|
if (err)
|
||||||
goto err_release_regions;
|
goto err_release_regions;
|
||||||
rvu->ptp = NULL;
|
rvu->ptp = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue