spi: sg2044-nor: A couple of cleanups
cover spi: sg2044-nor: A couple of cleanups
The driver has one ordering issue and one missed case for dev_err_probe(). Address that in this mini-series.
Andy Shevchenko (2):
spi: sg2044-nor: Fully convert to device managed resources
spi: sg2044-nor: Convert to dev_err_probe()
drivers/spi/spi-sg2044-nor.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-)
Signature · 1 line
2.47.2
PATCH 1/2 spi: sg2044-nor: Fully convert to device managed resources
The driver has a wrong order of the cleaning up the resources, i.e. it first will destroy the mutex and only then free the SPI which might still use it. Fix this by switching to devm_mutex_init().
--- drivers/spi/spi-sg2044-nor.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/spi/spi-sg2044-nor.c +3 -11
@@ -435,7 +435,6 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)return -ENOMEM ; spifmc =spi_controller_get_devdata (ctrl); -dev_set_drvdata (&pdev->dev, ctrl); spifmc->clk =devm_clk_get_enabled (&pdev->dev,NULL );if (IS_ERR (spifmc->clk))
@@ -457,14 +456,15 @@ static int sg2044_spifmc_probe(struct platform_device *pdev) ctrl->mem_ops = &sg2044_spifmc_mem_ops; ctrl->mode_bits =SPI_RX_DUAL |SPI_TX_DUAL |SPI_RX_QUAD |SPI_TX_QUAD ; -mutex_init (&spifmc->lock); + ret =devm_mutex_init (&spifmc->lock); +if (ret) +return ret;sg2044_spifmc_init (spifmc);sg2044_spifmc_init_reg (spifmc); ret =devm_spi_register_controller (&pdev->dev, ctrl);if (ret) { -mutex_destroy (&spifmc->lock);dev_err (&pdev->dev,"spi_register_controller failed\n" );return ret; }
@@ -472,13 +472,6 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)return 0 ; } -static void sg2044_spifmc_remove (struct platform_device *pdev) -{ -struct sg2044_spifmc *spifmc =platform_get_drvdata (pdev); - -mutex_destroy (&spifmc->lock); -} -static const struct of_device_id sg2044_spifmc_match[] = { { .compatible ="sophgo,sg2044-spifmc-nor" }, {/* sentinel */ }
@@ -491,7 +484,6 @@ static struct platform_driver sg2044_nor_driver = { .of_match_table = sg2044_spifmc_match, }, .probe = sg2044_spifmc_probe, - .remove = sg2044_spifmc_remove, };module_platform_driver (sg2044_nor_driver);
Signature · 1 line
2.47.2
kernel test robot
build botRe: [PATCH v1 1/2] spi: sg2044-nor: Fully convert to device managed resources
kernel test robot noticed the following build errors:
Hi Andy,
kernel test robot noticed the following build errors:
[auto build test ERROR on broonie-spi/for-next]
[cannot apply to linus/master v6.14-rc6 next-20250312]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/spi-sg2044-nor-Fully-convert-to-device-managed-resources/20250313-012347 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next patch link: https://lore.kernel.org/r/20250312172016.4070094-2-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v1 1/2] spi: sg2044-nor: Fully convert to device managed resources config: sh-allyesconfig (https://download.01.org/0day-ci/archive/20250313/[email protected]/config) compiler: sh4-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/spi/spi-sg2044-nor.c: In function 'sg2044_spifmc_probe':
>> drivers/spi/spi-sg2044-nor.c:459:44: error: macro "devm_mutex_init" requires 2 arguments, but only 1 given
459 | ret = devm_mutex_init(&spifmc->lock);
| ^
In file included from include/linux/notifier.h:14,
from include/linux/clk.h:14,
from drivers/spi/spi-sg2044-nor.c:9:
include/linux/mutex.h:144:9: note: macro "devm_mutex_init" defined here
144 | #define devm_mutex_init(dev, mutex) \
| ^~~~~~~~~~~~~~~
>> drivers/spi/spi-sg2044-nor.c:459:15: error: 'devm_mutex_init' undeclared (first use in this function)
459 | ret = devm_mutex_init(&spifmc->lock);
| ^~~~~~~~~~~~~~~ drivers/spi/spi-sg2044-nor.c:459:15: note: each undeclared identifier is reported only once for each function it appears in
vim +/devm_mutex_init +459 drivers/spi/spi-sg2044-nor.c
425
426 static int sg2044_spifmc_probe(struct platform_device *pdev)
427 {
428 struct spi_controller *ctrl;
429 struct sg2044_spifmc *spifmc;
430 void __iomem *base;
431 int ret;
432
433 ctrl = devm_spi_alloc_host(&pdev->dev, sizeof(*spifmc));
434 if (!ctrl)
435 return -ENOMEM;
436
437 spifmc = spi_controller_get_devdata(ctrl);
438
439 spifmc->clk = devm_clk_get_enabled(&pdev->dev, NULL);
440 if (IS_ERR(spifmc->clk))
441 return dev_err_probe(&pdev->dev, PTR_ERR(spifmc->clk),
442 "%s: Cannot get and enable AHB clock\n",
443 __func__);
444
445 spifmc->dev = &pdev->dev;
446 spifmc->ctrl = ctrl;
447
448 spifmc->io_base = devm_platform_ioremap_resource(pdev, 0);
449 if (IS_ERR(base))
450 return PTR_ERR(base);
451
452 ctrl->num_chipselect = 1;
453 ctrl->dev.of_node = pdev->dev.of_node;
454 ctrl->bits_per_word_mask = SPI_BPW_MASK(8);
455 ctrl->auto_runtime_pm = false;
456 ctrl->mem_ops = &sg2044_spifmc_mem_ops;
457 ctrl->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | SPI_RX_QUAD | SPI_TX_QUAD;
458
> 459 ret = devm_mutex_init(&spifmc->lock);
460 if (ret)
461 return ret;
462
463 sg2044_spifmc_init(spifmc);
464 sg2044_spifmc_init_reg(spifmc);
465
466 ret = devm_spi_register_controller(&pdev->dev, ctrl);
467 if (ret) {
468 dev_err(&pdev->dev, "spi_register_controller failed\n");
469 return ret;
470 }
471
472 return 0;
473 }
474
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v1 1/2] spi: sg2044-nor: Fully convert to device managed resources
Quoted 18 lines · kernel test robot
Hi Andy,
kernel test robot noticed the following build errors:
[auto build test ERROR on broonie-spi/for-next]
[cannot apply to linus/master v6.14-rc6 next-20250312]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/spi-sg2044-nor-Fully-convert-to-device-managed-resources/20250313-012347 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next patch link: https://lore.kernel.org/r/20250312172016.4070094-2-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v1 1/2] spi: sg2044-nor: Fully convert to device managed resources config: sh-allyesconfig (https://download.01.org/0day-ci/archive/20250313/[email protected]/config) compiler: sh4-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/[email protected]/reproduce)
Quoted 6 lines
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
Oh, indeed, missed the compilation of this module somehow. Will be fixed in v2, thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
kernel test robot
build botRe: [PATCH v1 1/2] spi: sg2044-nor: Fully convert to device managed resources
In reply to Andy Shevchenkokernel test robot noticed the following build errors:
Hi Andy,
kernel test robot noticed the following build errors:
[auto build test ERROR on broonie-spi/for-next]
[cannot apply to linus/master v6.14-rc6 next-20250312]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/spi-sg2044-nor-Fully-convert-to-device-managed-resources/20250313-012347 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next patch link: https://lore.kernel.org/r/20250312172016.4070094-2-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v1 1/2] spi: sg2044-nor: Fully convert to device managed resources config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20250313/[email protected]/config) compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250313/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/spi/spi-sg2044-nor.c:11:
In file included from include/linux/module.h:19:
In file included from include/linux/elf.h:6:
In file included from arch/s390/include/asm/elf.h:181:
In file included from arch/s390/include/asm/mmu_context.h:11:
In file included from arch/s390/include/asm/pgalloc.h:18:
In file included from include/linux/mm.h:2224:
include/linux/vmstat.h:504:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
504 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
505 | item];
| ~~~~
include/linux/vmstat.h:511:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
511 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
512 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:524:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
524 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
525 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
>> drivers/spi/spi-sg2044-nor.c:459:37: error: too few arguments provided to function-like macro invocation
459 | ret = devm_mutex_init(&spifmc->lock);
| ^
include/linux/mutex.h:144:9: note: macro 'devm_mutex_init' defined here
144 | #define devm_mutex_init(dev, mutex) \
| ^
>> drivers/spi/spi-sg2044-nor.c:459:8: error: use of undeclared identifier 'devm_mutex_init'; did you mean '__devm_mutex_init'?
459 | ret = devm_mutex_init(&spifmc->lock);
| ^~~~~~~~~~~~~~~
| __devm_mutex_init
include/linux/mutex.h:129:5: note: '__devm_mutex_init' declared here
129 | int __devm_mutex_init(struct device *dev, struct mutex *lock);
| ^3 warnings and 2 errors generated.
vim +459 drivers/spi/spi-sg2044-nor.c
425
426 static int sg2044_spifmc_probe(struct platform_device *pdev)
427 {
428 struct spi_controller *ctrl;
429 struct sg2044_spifmc *spifmc;
430 void __iomem *base;
431 int ret;
432
433 ctrl = devm_spi_alloc_host(&pdev->dev, sizeof(*spifmc));
434 if (!ctrl)
435 return -ENOMEM;
436
437 spifmc = spi_controller_get_devdata(ctrl);
438
439 spifmc->clk = devm_clk_get_enabled(&pdev->dev, NULL);
440 if (IS_ERR(spifmc->clk))
441 return dev_err_probe(&pdev->dev, PTR_ERR(spifmc->clk),
442 "%s: Cannot get and enable AHB clock\n",
443 __func__);
444
445 spifmc->dev = &pdev->dev;
446 spifmc->ctrl = ctrl;
447
448 spifmc->io_base = devm_platform_ioremap_resource(pdev, 0);
449 if (IS_ERR(base))
450 return PTR_ERR(base);
451
452 ctrl->num_chipselect = 1;
453 ctrl->dev.of_node = pdev->dev.of_node;
454 ctrl->bits_per_word_mask = SPI_BPW_MASK(8);
455 ctrl->auto_runtime_pm = false;
456 ctrl->mem_ops = &sg2044_spifmc_mem_ops;
457 ctrl->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | SPI_RX_QUAD | SPI_TX_QUAD;
458
> 459 ret = devm_mutex_init(&spifmc->lock);
460 if (ret)
461 return ret;
462
463 sg2044_spifmc_init(spifmc);
464 sg2044_spifmc_init_reg(spifmc);
465
466 ret = devm_spi_register_controller(&pdev->dev, ctrl);
467 if (ret) {
468 dev_err(&pdev->dev, "spi_register_controller failed\n");
469 return ret;
470 }
471
472 return 0;
473 }
474
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 2/2 spi: sg2044-nor: Convert to dev_err_probe()
In reply to Andy ShevchenkoOne of the cases in sg2044_spifmc_probe() may be converted to use dev_err_probe(). Do it.
While at it, use local device pointer in all such calls and drop unneeded __func__ parameter as dev_err_probe() is assumed to be called only during probe phase.
--- drivers/spi/spi-sg2044-nor.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/spi/spi-sg2044-nor.c +4 -7
@@ -425,6 +425,7 @@ static void sg2044_spifmc_init(struct sg2044_spifmc *spifmc)static int sg2044_spifmc_probe (struct platform_device *pdev) { +struct device *dev = &pdev->dev;struct spi_controller *ctrl;struct sg2044_spifmc *spifmc;void __iomem *base;
@@ -438,9 +439,7 @@ static int sg2044_spifmc_probe(struct platform_device *pdev) spifmc->clk =devm_clk_get_enabled (&pdev->dev,NULL );if (IS_ERR (spifmc->clk)) -return dev_err_probe (&pdev->dev,PTR_ERR (spifmc->clk), -"%s: Cannot get and enable AHB clock\n" , - __func__); +return dev_err_probe (dev,PTR_ERR (spifmc->clk),"Cannot get and enable AHB clock\n" ); spifmc->dev = &pdev->dev; spifmc->ctrl = ctrl;
@@ -464,10 +463,8 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)sg2044_spifmc_init_reg (spifmc); ret =devm_spi_register_controller (&pdev->dev, ctrl); -if (ret) { -dev_err (&pdev->dev,"spi_register_controller failed\n" ); -return ret; - } +if (ret) +return dev_err_probe (dev, ret,"spi_register_controller failed\n" );return 0 ; }
Signature · 1 line
2.47.2