spi: mt7621: Fix an erroneous message + clean-ups
Subsystems (3)
cover spi: mt7621: Fix an erroneous message + clean-ups
Patch 1 fixes an issue about an error code that is erroneously logged.
Patch 2-4 are just clean-ups spotted while fixing it.
Additional comments are added below --- in patches 2 and 3.
Christophe JAILLET (4):
spi: mt7621: Fix an error message in mt7621_spi_probe()
spi: mt7621: Use the devm_clk_get_enabled() helper to simplify error
handling
spi: mt7621: Use devm_spi_register_controller()
spi: mt7621: Remove 'clk' from 'struct mt7621_spi'
drivers/spi/spi-mt7621.c | 42 ++++++---------------------------------- 1 file changed, 6 insertions(+), 36 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 spi: mt7621: Fix an error message in mt7621_spi_probe()
'status' is known to be 0 at this point. The expected error code is PTR_ERR(clk).
Switch to dev_err_probe() in order to display the expected error code (in a human readable way).
This also filters -EPROBE_DEFER cases, should it happen.
--- drivers/spi/spi-mt7621.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/spi/spi-mt7621.c +3 -5
@@ -340,11 +340,9 @@ static int mt7621_spi_probe(struct platform_device *pdev)return PTR_ERR (base); clk =devm_clk_get (&pdev->dev,NULL ); -if (IS_ERR (clk)) { -dev_err (&pdev->dev,"unable to get SYS clock, err=%d\n" , - status); -return PTR_ERR (clk); - } +if (IS_ERR (clk)) +return dev_err_probe (&pdev->dev,PTR_ERR (clk), +"unable to get SYS clock\n" ); status =clk_prepare_enable (clk);if (status)
Signature · 1 line
2.34.1
Re: [PATCH 1/4] spi: mt7621: Fix an error message in mt7621_spi_probe()
Quoted 9 lines · Christophe JAILLET
'status' is known to be 0 at this point. The expected error code is
PTR_ERR(clk).Switch to
dev_err_probe()in order to display the expected error code (in a human readable way).
This also filters -EPROBE_DEFER cases, should it happen.Fixes 1ab7f2a43558 ("staging: mt7621-spi: add mt7621 support")Signed-off-by Christophe JAILLET <[email protected]>
Quoted 23 lines
--- drivers/spi/spi-mt7621.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/spi/spi-mt7621.c +3
-5@@ -340,11 +340,9 @@ static int mt7621_spi_probe(struct platform_device *pdev)return PTR_ERR (base); clk =devm_clk_get (&pdev->dev,NULL ); -if (IS_ERR (clk)) { -dev_err (&pdev->dev,"unable to get SYS clock, err=%d\n" , - status); -return PTR_ERR (clk); - } +if (IS_ERR (clk)) +return dev_err_probe (&pdev->dev,PTR_ERR (clk), +"unable to get SYS clock\n" ); status =clk_prepare_enable (clk);if (status)
Re: [PATCH 1/4] spi: mt7621: Fix an error message in mt7621_spi_probe()
In reply to Christophe JAILLETIl 27/08/22 13:42, Christophe JAILLET ha scritto:
Quoted 10 lines
'status' is known to be 0 at this point. The expected error code is
PTR_ERR(clk).Switch to
dev_err_probe()in order to display the expected error code (in a human readable way).
This also filters -EPROBE_DEFER cases, should it happen.Fixes 1ab7f2a43558 ("staging: mt7621-spi: add mt7621 support")Signed-off-by Christophe JAILLET <[email protected]>Reviewed-by Matthias Brugger <[email protected]>
PATCH 2/4 spi: mt7621: Use the devm_clk_get_enabled() helper to simplify error handling
In reply to Christophe JAILLETThe devm_clk_get_enabled() helper:
- calls devm_clk_get()
- calls clk_prepare_enable() and registers what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.
This helper is well suited for cases where the clock would be kept prepared or enabled for the whole lifetime of the driver.
This simplifies the error handling a lot.
The order between spi_unregister_controller() (in the remove function) and the clk_disable_unprepare() (now handle by a managed resource) is kept the same.
(see commit 46b5c4fb87ce ("spi: mt7621: Don't leak SPI master in probe error path") to see why it matters)
---
The order with devm_spi_release_controller() (which undoes devm_spi_alloc_master()) is reversed, but I don't think it is an issue.
--- drivers/spi/spi-mt7621.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/spi/spi-mt7621.c +1 -13
@@ -327,7 +327,6 @@ static int mt7621_spi_probe(struct platform_device *pdev)struct spi_controller *master;struct mt7621_spi *rs;void __iomem *base; -int status =0 ;struct clk *clk;int ret;
@@ -339,19 +338,14 @@ static int mt7621_spi_probe(struct platform_device *pdev)if (IS_ERR (base))return PTR_ERR (base); - clk =devm_clk_get (&pdev->dev,NULL ); + clk =devm_clk_get_enabled (&pdev->dev,NULL );if (IS_ERR (clk))return dev_err_probe (&pdev->dev,PTR_ERR (clk),"unable to get SYS clock\n" ); - status =clk_prepare_enable (clk); -if (status) -return status; - master =devm_spi_alloc_master (&pdev->dev,sizeof (*rs));if (!master) {dev_info (&pdev->dev,"master allocation failed\n" ); -clk_disable_unprepare (clk);return -ENOMEM ; }
@@ -376,13 +370,10 @@ static int mt7621_spi_probe(struct platform_device *pdev) ret =device_reset (&pdev->dev);if (ret) {dev_err (&pdev->dev,"SPI reset failed!\n" ); -clk_disable_unprepare (clk);return ret; } ret =spi_register_controller (master); -if (ret) -clk_disable_unprepare (clk);return ret; }
@@ -390,13 +381,10 @@ static int mt7621_spi_probe(struct platform_device *pdev)static int mt7621_spi_remove (struct platform_device *pdev) {struct spi_controller *master; -struct mt7621_spi *rs; master =dev_get_drvdata (&pdev->dev); - rs =spi_controller_get_devdata (master);spi_unregister_controller (master); -clk_disable_unprepare (rs->clk);return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH 2/4] spi: mt7621: Use the devm_clk_get_enabled() helper to simplify error handling
Quoted 10 lines · Christophe JAILLET
The
devm_clk_get_enabled()helper:
- callsdevm_clk_get()
- callsclk_prepare_enable()and registers what is needed in order to callclk_disable_unprepare()when needed, as a managed resource.This helper is well suited for cases where the clock would be kept prepared or enabled for the whole lifetime of the driver.
This simplifies the error handling a lot.
Quoted 7 lines
The order between
spi_unregister_controller()(in the remove function) and theclk_disable_unprepare()(now handle by a managed resource) is kept the same.
(see commit46b5c4fb87ce("spi: mt7621: Don't leak SPI master in probe error path") to see why it matters)Signed-off-by Christophe JAILLET <[email protected]>
Quoted 68 lines
---
The order withdevm_spi_release_controller()(which undoesdevm_spi_alloc_master()) is reversed, but I don't think it is an issue.--- drivers/spi/spi-mt7621.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)drivers/spi/spi-mt7621.c +1
-13@@ -327,7 +327,6 @@ static int mt7621_spi_probe(struct platform_device *pdev)struct spi_controller *master;struct mt7621_spi *rs;void __iomem *base; -int status =0 ;struct clk *clk;int ret;@@ -339,19 +338,14 @@ static int mt7621_spi_probe(struct platform_device *pdev)if (IS_ERR (base))return PTR_ERR (base); - clk =devm_clk_get (&pdev->dev,NULL ); + clk =devm_clk_get_enabled (&pdev->dev,NULL );if (IS_ERR (clk))return dev_err_probe (&pdev->dev,PTR_ERR (clk),"unable to get SYS clock\n" ); - status =clk_prepare_enable (clk); -if (status) -return status; - master =devm_spi_alloc_master (&pdev->dev,sizeof (*rs));if (!master) {dev_info (&pdev->dev,"master allocation failed\n" ); -clk_disable_unprepare (clk);return -ENOMEM ; }@@ -376,13 +370,10 @@ static int mt7621_spi_probe(struct platform_device *pdev) ret =device_reset (&pdev->dev);if (ret) {dev_err (&pdev->dev,"SPI reset failed!\n" ); -clk_disable_unprepare (clk);return ret; } ret =spi_register_controller (master); -if (ret) -clk_disable_unprepare (clk);return ret; }@@ -390,13 +381,10 @@ static int mt7621_spi_probe(struct platform_device *pdev)static int mt7621_spi_remove (struct platform_device *pdev) {struct spi_controller *master; -struct mt7621_spi *rs; master =dev_get_drvdata (&pdev->dev); - rs =spi_controller_get_devdata (master);spi_unregister_controller (master); -clk_disable_unprepare (rs->clk);return 0 ; }
Re: [PATCH 2/4] spi: mt7621: Use the devm_clk_get_enabled() helper to simplify error handling
In reply to Christophe JAILLETIl 27/08/22 13:42, Christophe JAILLET ha scritto:
Quoted 10 lines
The
devm_clk_get_enabled()helper:
- callsdevm_clk_get()
- callsclk_prepare_enable()and registers what is needed in order to callclk_disable_unprepare()when needed, as a managed resource.This helper is well suited for cases where the clock would be kept prepared or enabled for the whole lifetime of the driver.
This simplifies the error handling a lot.
Quoted 8 lines
The order between
spi_unregister_controller()(in the remove function) and theclk_disable_unprepare()(now handle by a managed resource) is kept the same.
(see commit46b5c4fb87ce("spi: mt7621: Don't leak SPI master in probe error path") to see why it matters)Signed-off-by Christophe JAILLET <[email protected]>Reviewed-by Matthias Brugger <[email protected]>
PATCH 3/4 spi: mt7621: Use devm_spi_register_controller()
In reply to Christophe JAILLETNow that clk_disable_unprepare(clk) is handled with a managed resource, we can use devm_spi_register_controller() and axe the .remove function.
The order between spi_unregister_controller() and clk_disable_unprepare() is still the same.
(see commit 46b5c4fb87ce ("spi: mt7621: Don't leak SPI master in probe error path") to see why it matters)
---
I guess that the dev_set_drvdata() in the probe can be removed as-well. But it is also harmless to leave it as-is.
--- drivers/spi/spi-mt7621.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
drivers/spi/spi-mt7621.c +1 -15
@@ -373,20 +373,7 @@ static int mt7621_spi_probe(struct platform_device *pdev)return ret; } - ret =spi_register_controller (master); - -return ret; -} - -static int mt7621_spi_remove (struct platform_device *pdev) -{ -struct spi_controller *master; - - master =dev_get_drvdata (&pdev->dev); - -spi_unregister_controller (master); - -return 0 ; +return devm_spi_register_controller (&pdev->dev, master); }MODULE_ALIAS ("platform:" DRIVER_NAME );
@@ -397,7 +384,6 @@ static struct platform_driver mt7621_spi_driver = { .of_match_table = mt7621_spi_match, }, .probe = mt7621_spi_probe, - .remove = mt7621_spi_remove, };module_platform_driver (mt7621_spi_driver);
Signature · 1 line
2.34.1
Re: [PATCH 3/4] spi: mt7621: Use devm_spi_register_controller()
Quoted 9 lines · Christophe JAILLET
Now that
clk_disable_unprepare(clk)is handled with a managed resource, we can usedevm_spi_register_controller()and axe the .remove function.The order between
spi_unregister_controller()andclk_disable_unprepare()is still the same.
(see commit46b5c4fb87ce("spi: mt7621: Don't leak SPI master in probe error path") to see why it matters)Signed-off-by Christophe JAILLET <[email protected]>
Quoted 41 lines
---
I guess that thedev_set_drvdata()in the probe can be removed as-well. But it is also harmless to leave it as-is.--- drivers/spi/spi-mt7621.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)drivers/spi/spi-mt7621.c +1
-15@@ -373,20 +373,7 @@ static int mt7621_spi_probe(struct platform_device *pdev)return ret; } - ret =spi_register_controller (master); - -return ret; -} - -static int mt7621_spi_remove (struct platform_device *pdev) -{ -struct spi_controller *master; - - master =dev_get_drvdata (&pdev->dev); - -spi_unregister_controller (master); - -return 0 ; +return devm_spi_register_controller (&pdev->dev, master); }MODULE_ALIAS ("platform:" DRIVER_NAME );@@ -397,7 +384,6 @@ static struct platform_driver mt7621_spi_driver = { .of_match_table = mt7621_spi_match, }, .probe = mt7621_spi_probe, - .remove = mt7621_spi_remove, };module_platform_driver (mt7621_spi_driver);
PATCH 4/4 spi: mt7621: Remove 'clk' from 'struct mt7621_spi'
In reply to Christophe JAILLETThe 'clk' field in 'struct mt7621_spi' is useless, remove it.
--- drivers/spi/spi-mt7621.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/spi/spi-mt7621.c +1 -3
@@ -55,7 +55,6 @@ struct mt7621_spi {void __iomem *base;unsigned int sys_freq;unsigned int speed; -struct clk *clk;int pending_write; };
@@ -361,9 +360,8 @@ static int mt7621_spi_probe(struct platform_device *pdev) rs =spi_controller_get_devdata (master); rs->base = base; - rs->clk = clk; rs->master = master; - rs->sys_freq =clk_get_rate (rs->clk); + rs->sys_freq =clk_get_rate (clk); rs->pending_write =0 ;dev_info (&pdev->dev,"sys_freq: %u\n" , rs->sys_freq);
Signature · 1 line
2.34.1
Matthias Brugger
maintainerRe: [PATCH 4/4] spi: mt7621: Remove 'clk' from 'struct mt7621_spi'
Quoted 3 lines · Christophe JAILLET
The 'clk' field in 'struct
mt7621_spi' is useless, remove it.Signed-off-by Christophe JAILLET <[email protected]>
IMHO should be part of patch 2/4.
Regards,
Matthias
Quoted 27 lines
--- drivers/spi/spi-mt7621.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/spi/spi-mt7621.c +1
-3@@ -55,7 +55,6 @@ struct mt7621_spi {void __iomem *base;unsigned int sys_freq;unsigned int speed; -struct clk *clk;int pending_write; };@@ -361,9 +360,8 @@ static int mt7621_spi_probe(struct platform_device *pdev) rs =spi_controller_get_devdata (master); rs->base = base; - rs->clk = clk; rs->master = master; - rs->sys_freq =clk_get_rate (rs->clk); + rs->sys_freq =clk_get_rate (clk); rs->pending_write =0 ;dev_info (&pdev->dev,"sys_freq: %u\n" , rs->sys_freq);
Re: [PATCH 4/4] spi: mt7621: Remove 'clk' from 'struct mt7621_spi'
Le 29/08/2022 à 13:18, Matthias Brugger a écrit :
Quoted 8 lines · Christophe JAILLET
Quoted 3 lines
The 'clk' field in 'struct
mt7621_spi' is useless, remove it.Signed-off-by Christophe JAILLET <[email protected]>IMHO should be part of patch 2/4.
Ok, I'll send a v2 of the serie to merge patch 2 & 4.
CJ
Quoted 29 lines
Regards,
MatthiasQuoted 25 lines
---
drivers/spi/spi-mt7621.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)drivers/spi/spi-mt7621.c +1
-3@@ -55,7 +55,6 @@ struct mt7621_spi { void __iomem *base; unsigned int sys_freq; unsigned int speed; - struct clk *clk; int pending_write; };@@ -361,9 +360,8 @@ static int mt7621_spi_probe(struct platform_device *pdev) rs = spi_controller_get_devdata(master); rs->base = base; - rs->clk = clk; rs->master = master; - rs->sys_freq = clk_get_rate(rs->clk); + rs->sys_freq = clk_get_rate(clk); rs->pending_write = 0; dev_info(&pdev->dev, "sys_freq: %u\n", rs->sys_freq);
Mark Brown
maintainerQuoted 6 lines · Christophe JAILLET
Patch 1 fixes an issue about an error code that is erroneously logged.
Patch 2-4 are just clean-ups spotted while fixing it.
Additional comments are added below --- in patches 2 and 3.
Quoted 8 lines
Christophe JAILLET (4):
spi: mt7621: Fix an error message inmt7621_spi_probe()
spi: mt7621: Use thedevm_clk_get_enabled()helper to simplify error
handling
spi: mt7621: Usedevm_spi_register_controller()
spi: mt7621: Remove 'clk' from 'structmt7621_spi'[...]
Applied to
broonie/spi.git for-next
Thanks!
[1/4] spi: mt7621: Fix an error message in mt7621_spi_probe()
commit: 2b2bf6b7faa9010fae10dc7de76627a3fdb525b3
[2/4] spi: mt7621: Use the devm_clk_get_enabled() helper to simplify error handling
commit: 3d6af96814d753f34cf897466e7ddf041d0cdf3b
[3/4] spi: mt7621: Use devm_spi_register_controller()
commit: 30b31b29a866d32fc381b406d4c4f5db2636e5ec
[4/4] spi: mt7621: Remove 'clk' from 'struct mt7621_spi'
commit: 4a5cc683543f5f6ed586944095c65cb4da4b9273All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark