[PATCH] spi: spi-cadence-quadspi: Fix division by zero warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fix below division by zero warning:
- Added an if statement because buswidth can be zero, resulting in division by zero.
- The modified code was based on another driver (atmel-quadspi).

[    0.795337] Division by zero in kernel.
[    0.797878] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.12.0-xxx-xxxx+ #1
[    0.803782] Hardware name: Altera SOCFPGA
[    0.806481] Backtrace:
[    0.807628] [<807fd2b0>] (dump_backtrace) from [<807fd554>] (show_stack+0x20/0x24)
[    0.813899]  r7:00000000 r6:60000013 r5:00000000 r4:80de1db8
[    0.818239] [<807fd534>] (show_stack) from [<80800e84>] (dump_stack+0xa8/0xc8)
[    0.824147] [<80800ddc>] (dump_stack) from [<807fd430>] (__div0+0x24/0x28)
[    0.829712]  r7:00000000 r6:812edac0 r5:812edac0 r4:810ff9b0
[    0.834051] [<807fd40c>] (__div0) from [<804e1acc>] (Ldiv0+0x8/0x10)
[    0.839097] [<805f0710>] (cqspi_exec_mem_op) from [<805edb4c>] (spi_mem_exec_op+0x3b0/0x3f8)
[    0.846230]  r10:81d45c00 r9:812ed800 r8:812ed800 r7:810fe000 r6:81d47bc0 r5:810ff9b0
[    0.852731]  r4:00000000
[    0.853958] [<805ed79c>] (spi_mem_exec_op) from [<805df090>] (spi_nor_read_id+0x88/0x178)
[    0.860827]  r10:81d45c00 r9:0000000f r8:80946d4c r7:81c32040 r6:80946f38 r5:81d45d20
[    0.867328]  r4:81d47bc0
[    0.868556] [<805df008>] (spi_nor_read_id) from [<805e00cc>] (spi_nor_scan+0x920/0xa80)
[    0.875247]  r10:81d45c00 r9:0000000f r8:80946d4c r7:80946d78 r6:80946f38 r5:81d45d20
[    0.881748]  r4:81d41c40
[    0.882976] [<805df7ac>] (spi_nor_scan) from [<805e1388>] (spi_nor_probe+0xac/0x2d8)
[    0.889409]  r10:00000000 r9:80dee720 r8:00000000 r7:810fe000 r6:81d45c00 r5:81d45d20
[    0.895910]  r4:81d41c40
[    0.897138] [<805e12dc>] (spi_nor_probe) from [<805ed198>] (spi_mem_probe+0x94/0xa0)
[    0.903571]  r8:00000001 r7:812ed800 r6:80dee720 r5:81d47bc0 r4:81d45c00
[    0.908947] [<805ed104>] (spi_mem_probe) from [<805e6934>] (spi_probe+0x78/0x8c)
[    0.915030]  r7:80ea6844 r6:80dee710 r5:81d45c00 r4:00000000
[    0.919368] [<805e68bc>] (spi_probe) from [<805894c4>] (really_probe+0xf4/0x4b0)
[    0.925458]  r7:80ea6844 r6:00000000 r5:80ea683c r4:81d45c00
[    0.929796] [<805893d0>] (really_probe) from [<80589de8>] (__device_attach_driver+0x114/0x144)
[    0.937095]  r10:00000000 r9:80ea6814 r8:00000001 r7:81d45c00 r6:810ffbac r5:80dee720
[    0.943596]  r4:00000001
[    0.944824] [<80589cd4>] (__device_attach_driver) from [<805872e4>] (bus_for_each_drv+0x94/0xd8)
[    0.952294]  r7:80589cd4 r6:810fe000 r5:810ffbac r4:00000000
[    0.956633] [<80587250>] (bus_for_each_drv) from [<80589a74>] (__device_attach+0x104/0x15c)
[    0.963669]  r7:812ed800 r6:81d45c44 r5:810fe000 r4:81d45c00
[    0.968008] [<80589970>] (__device_attach) from [<80589e34>] (device_initial_probe+0x1c/0x20)
[    0.975219]  r8:00000000 r7:812ed800 r6:81d45c00 r5:80dee7cc r4:81d45c00
[    0.980595] [<80589e18>] (device_initial_probe) from [<8058855c>] (bus_probe_device+0x94/0x9c)
[    0.987888] [<805884c8>] (bus_probe_device) from [<80584fd4>] (device_add+0x318/0x7cc)
[    0.994491]  r7:812ed800 r6:810fe000 r5:00000000 r4:81d45c00
[    0.998830] [<80584cbc>] (device_add) from [<805eab2c>] (spi_add_device+0xc0/0x16c)
[    1.005175]  r10:0000010a r9:00000001 r8:00000000 r7:8122c210 r6:812ed800 r5:81d45c00
[    1.011675]  r4:00000000
[    1.012903] [<805eaa6c>] (spi_add_device) from [<805eaf34>] (of_register_spi_device+0x248/0x374)
[    1.020371]  r7:812ed800 r6:810fe000 r5:9fbf25e8 r4:81d45c00
[    1.024709] [<805eacec>] (of_register_spi_device) from [<805eb748>] (spi_register_controller+0x6e8/0x870)
[    1.032956]  r9:80dee8b0 r8:80a2f8f8 r7:9fbf264c r6:9fbf25e8 r5:00000000 r4:812ed800
[    1.039369] [<805eb060>] (spi_register_controller) from [<805eb914>] (devm_spi_register_controller+0x44/0x7c)
[    1.047963]  r10:80a237d8 r9:80a300ac r8:8122c210 r7:8122c210 r6:812ed800 r5:00000000
[    1.054463]  r4:81d47a40
[    1.055690] [<805eb8d0>] (devm_spi_register_controller) from [<805f044c>] (cqspi_probe+0x648/0x90c)
[    1.063418]  r7:00000000 r6:00000000 r5:00000000 r4:812edac0
[    1.067757] [<805efe04>] (cqspi_probe) from [<8058baec>] (platform_probe+0x58/0x9c)
[    1.074103]  r10:00000000 r9:80def484 r8:00000000 r7:80ea6844 r6:00000000 r5:80def484
[    1.080604]  r4:8122c210
[    1.081832] [<8058ba94>] (platform_probe) from [<805894c4>] (really_probe+0xf4/0x4b0)
[    1.088346]  r5:80ea683c r4:8122c210
[    1.090610] [<805893d0>] (really_probe) from [<80589f2c>] (device_driver_attach+0xf4/0x104)
[    1.097649]  r10:80e13000 r9:80b35854 r8:00000000 r7:8122c254 r6:80def484 r5:00000000
[    1.104150]  r4:8122c210
[    1.105377] [<80589e38>] (device_driver_attach) from [<80589fcc>] (__driver_attach+0x90/0x120)
[    1.112675]  r7:00000000 r6:8122c210 r5:80def484 r4:00000000
[    1.117014] [<80589f3c>] (__driver_attach) from [<80587210>] (bus_for_each_dev+0x88/0xc8)
[    1.123878]  r7:00000000 r6:810fe000 r5:80589f3c r4:80def484
[    1.128217] [<80587188>] (bus_for_each_dev) from [<80588d9c>] (driver_attach+0x2c/0x30)
[    1.134907]  r7:80de8b20 r6:00000000 r5:81d47580 r4:80def484
[    1.139246] [<80588d70>] (driver_attach) from [<80588774>] (bus_add_driver+0x108/0x1f0)
[    1.145934] [<8058866c>] (bus_add_driver) from [<8058a6ec>] (driver_register+0x9c/0x134)
[    1.152712]  r7:ffffe000 r6:80b22718 r5:00000000 r4:80def484
[    1.157050] [<8058a650>] (driver_register) from [<8058b810>] (__platform_driver_register+0x2c/0x34)
[    1.164776]  r5:80e07c60 r4:810fe000
[    1.167040] [<8058b7e4>] (__platform_driver_register) from [<80b2273c>] (cqspi_platform_driver_init+0x24/0x28)
[    1.175721] [<80b22718>] (cqspi_platform_driver_init) from [<80102414>] (do_one_initcall+0x60/0x2cc)
[    1.183535] [<801023b4>] (do_one_initcall) from [<80b01278>] (kernel_init_freeable+0x26c/0x2dc)
[    1.190924]  r8:80e07c60 r7:811d0240 r6:80b35834 r5:00000007 r4:80b59980
[    1.196300] [<80b0100c>] (kernel_init_freeable) from [<80806518>] (kernel_init+0x18/0x130)
[    1.203257]  r10:00000000 r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:80806500
[    1.209758]  r4:00000000
[    1.210986] [<80806500>] (kernel_init) from [<801000fc>] (ret_from_fork+0x14/0x38)
[    1.217239] Exception stack(0x810fffb0 to 0x810ffff8)
[    1.220979] ffa0:                                     00000000 00000000 00000000 00000000
[    1.227831] ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    1.234680] ffe0: 00000000 00000000 00000000 00000000 00000013 00000000
[    1.239973]  r5:80806500 r4:00000000

Signed-off-by: Yoshitaka Ikeda <ikeda@xxxxxxxxxxxx>
---
  drivers/spi/spi-cadence-quadspi.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 7a00346ff9b9..13d1f0ce618e 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -307,11 +307,13 @@ static unsigned int cqspi_calc_rdreg(struct cqspi_flash_pdata *f_pdata)
  
  static unsigned int cqspi_calc_dummy(const struct spi_mem_op *op, bool dtr)
  {
-	unsigned int dummy_clk;
+	unsigned int dummy_clk = 0;
  
-	dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth);
-	if (dtr)
-		dummy_clk /= 2;
+	if (op->dummy.buswidth && op->dummy.nbytes) {
+		dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth);
+		if (dtr)
+			dummy_clk /= 2;
+	}
  
  	return dummy_clk;
  }
-- 
2.32.0




[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux