PCI: j721e: In j721e_pcie_suspend_noirq() check reset_gpio before to use it
Subsystems (5)
PATCH 1/1 PCI: j721e: In j721e_pcie_suspend_noirq() check reset_gpio before to use it
The reset_gpio is optional, so in j721e_pcie_suspend_noirq() check if it is not NULL before to use it.
--- drivers/pci/controller/cadence/pci-j721e.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/controller/cadence/pci-j721e.c +3 -1
@@ -644,7 +644,9 @@ static int j721e_pcie_suspend_noirq(struct device *dev)struct j721e_pcie *pcie =dev_get_drvdata (dev);if (pcie->mode ==PCI_MODE_RC ) { -gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +if (pcie->reset_gpio) +gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +clk_disable_unprepare (pcie->refclk); }
Signature · 1 line
2.39.5
Quoted 5 lines · Thomas Richard
The
reset_gpiois optional, so inj721e_pcie_suspend_noirq()check if it is not NULL before to use it.Fixes c538d40f365b ("PCI: j721e: Add suspend and resume support")Signed-off-by Thomas Richard <[email protected]>
Quoted 9 lines
--- drivers/pci/controller/cadence/pci-j721e.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/pci/controller/cadence/pci-j721e.c +0
-0
drivers/pci/controller/cadence/pci-j721e.c static int j721e_pcie_suspend_noirq(struct device *dev) · line 652
Quoted 10 lines
drivers/pci/controller/cadence/pci-j721e.c +3
-1@@ -644,7 +644,9 @@ static int j721e_pcie_suspend_noirq(struct device *dev)struct j721e_pcie *pcie =dev_get_drvdata (dev);if (pcie->mode ==PCI_MODE_RC ) { -gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +if (pcie->reset_gpio) +gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +clk_disable_unprepare (pcie->refclk); }
Regards,
Siddharth.
Quoted 2 lines · Thomas Richard
The
reset_gpiois optional, so inj721e_pcie_suspend_noirq()check if it is not NULL before to use it.
If you have occasion to post a v2, update subject to:
PCI: j721e: Check reset_gpio for NULL before using it
s/before to use it/before using it/
Did you trip over a NULL pointer dereference here? Or maybe found via inspection?
It looks like gpiod_set_value_cansleep(desc) *should* be a no-op if desc is NULL, based on this comment [1]:
* This descriptor validation needs to be inserted verbatim into each
* function taking a descriptor, so we need to use a preprocessor
* macro to avoid endless duplication. If the desc is NULL it is an
* optional GPIO and calls should just bail out.
and the fact that the VALIDATE_DESC_VOID() macro looks like it would return early in that case.
Quoted 24 lines
Fixes c538d40f365b ("PCI: j721e: Add suspend and resume support")Signed-off-by Thomas Richard <[email protected]>--- drivers/pci/controller/cadence/pci-j721e.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/pci/controller/cadence/pci-j721e.c +3
-1@@ -644,7 +644,9 @@ static int j721e_pcie_suspend_noirq(struct device *dev)struct j721e_pcie *pcie =dev_get_drvdata (dev);if (pcie->mode ==PCI_MODE_RC ) { -gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +if (pcie->reset_gpio) +gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +clk_disable_unprepare (pcie->refclk); }Signature · 1 line
2.39.5
Quoted 4 lines · Bjorn Helgaas
Quoted 2 lines · Thomas Richard
The
reset_gpiois optional, so inj721e_pcie_suspend_noirq()check if it is not NULL before to use it.
Quoted 8 lines
If you have occasion to post a v2, update subject to:
PCI: j721e: Check
reset_gpiofor NULL before using its/before to use it/before using it/
Did you trip over a NULL pointer dereference here? Or maybe found via inspection?
By inspection
Quoted 9 lines
It looks like
gpiod_set_value_cansleep(desc)*should* be a no-op if desc is NULL, based on this comment [1]:* This descriptor validation needs to be inserted verbatim into each
* function taking a descriptor, so we need to use a preprocessor
* macro to avoid endless duplication. If the desc is NULL it is an
* optional GPIO and calls should just bail out.
Quoted 4 lines
and the fact that the
VALIDATE_DESC_VOID()macro looks like it would return early in that case.
Oh yes you're right.
In fact, the if statement in probe() and resume_noirq() is for msleep(), not really for gpiod_set_value_cansleep().
So this patch is useless.
Regards,
Thomas
Quoted 28 lines · Thomas Richard
Quoted 4 lines · Bjorn Helgaas
Quoted 2 lines · Thomas Richard
The
reset_gpiois optional, so inj721e_pcie_suspend_noirq()check if it is not NULL before to use it.Quoted 8 lines
If you have occasion to post a v2, update subject to:
PCI: j721e: Check
reset_gpiofor NULL before using its/before to use it/before using it/
Did you trip over a NULL pointer dereference here? Or maybe found via inspection?
By inspection
Quoted 12 lines
It looks like
gpiod_set_value_cansleep(desc)*should* be a no-op if desc is NULL, based on this comment [1]:* This descriptor validation needs to be inserted verbatim into each
* function taking a descriptor, so we need to use a preprocessor
* macro to avoid endless duplication. If the desc is NULL it is an
* optional GPIO and calls should just bail out.and the fact that the
VALIDATE_DESC_VOID()macro looks like it would return early in that case.
Quoted 8 lines
Quoted 1 line
Oh yes you're right.
In fact, the if statement inprobe()andresume_noirq()is formsleep(), not really forgpiod_set_value_cansleep().So this patch is useless.
Yes. Almost all of the GPIO APIs accepting desc (except few) use VALIDATE_DESC() to check for NULL descriptor. So explicit check is not needed.
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
[+cc GPIO folks in case they think it's worthwhile to document that it's safe to pass NULL pointers to gpiod_*() interfaces]
Quoted 26 lines · Manivannan Sadhasivam
Quoted 25 lines · Thomas Richard
Quoted 24 lines · Bjorn Helgaas
Quoted 5 lines · Thomas Richard
The
reset_gpiois optional, so inj721e_pcie_suspend_noirq()check if it is not NULL before to use it.+++
b/drivers/pci/controller/cadence/pci-j721e.cdrivers/pci/controller/cadence/pci-j721e.c static int j721e_pcie_suspend_noirq(struct device *dev) · line 651
Quoted 9 lines
drivers/pci/controller/cadence/pci-j721e.c +3
-1@@ -644,7 +644,9 @@ static int j721e_pcie_suspend_noirq(struct device *dev)struct j721e_pcie *pcie =dev_get_drvdata (dev);if (pcie->mode ==PCI_MODE_RC ) { -gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +if (pcie->reset_gpio) +gpiod_set_value_cansleep (pcie->reset_gpio,0 ); +clk_disable_unprepare (pcie->refclk); }It looks like
gpiod_set_value_cansleep(desc)*should* be a no-op if desc is NULL, based on this comment [1]:* This descriptor validation needs to be inserted verbatim into each
* function taking a descriptor, so we need to use a preprocessor
* macro to avoid endless duplication. If the desc is NULL it is an
* optional GPIO and calls should just bail out.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
and the fact that the
VALIDATE_DESC_VOID()macro looks like it would return early in that case.Yes. Almost all of the GPIO APIs accepting desc (except few) use
VALIDATE_DESC()to check for NULL descriptor. So explicit check is not needed.
I think it would be nice if the kernel-doc for these functions mentioned this somewhere. It's kind of a pain for every user to have to deduce this.
Bjorn