Skip to contentSkip to conversation

staging: sm750fb: use proper error codes instead of -1

PATCH In review Soham Kute 2 participants 22 messages Mar 1 – Mar 5

Subsystems (3)
lore
Share & tools
lore

Soham Kute

author
#0 lore raw

PATCH 1/1 staging: sm750fb: use proper error codes instead of -1

Replace magic return value -1 with proper kernel error codes -EBUSY, -ETIMEDOUT and -EINVAL.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 4 ++--
 drivers/staging/sm750fb/sm750_accel.c  | 6 +++---
 drivers/staging/sm750fb/sm750_hw.c     | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +2 -2
index 0ef8d4ff2ef9..d90a93ab8fdc 100644
@@ -294,7 +294,7 @@ static long sw_i2c_write_byte(unsigned char data)
 	if (i < 0xff)
 		return 0;
 	else
-		return -1;
+		return -ETIMEDOUT;
 }
 
 /*
@@ -394,7 +394,7 @@ long sm750_sw_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
 	 * range is only from [0..63]
 	 */
 	if ((clk_gpio > 31) || (data_gpio > 31))
-		return -1;
+		return -EINVAL;
 
 	if (sm750_get_chip_type() == SM750LE)
 		return sm750le_i2c_init(clk_gpio, data_gpio);
drivers/staging/sm750fb/sm750_accel.c +3 -3
index 046b9282b24a..fa593d4f31fe 100644
@@ -97,7 +97,7 @@ int sm750_hw_fillrect(struct lynx_accel *accel,
 		 * got something error
 		 */
 		pr_debug("De engine always busy\n");
-		return -1;
+		return -EBUSY;
 	}
 
 	write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */
@@ -264,7 +264,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel,
 		  (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */
 
 	if (accel->de_wait() != 0)
-		return -1;
+		return -EBUSY;
 
 	write_dpr(accel, DE_SOURCE,
 		  ((sx << DE_SOURCE_X_K1_SHIFT) & DE_SOURCE_X_K1_MASK) |
@@ -333,7 +333,7 @@ int sm750_hw_imageblit(struct lynx_accel *accel, const char *pSrcbuf,
 	ulBytesRemain = ulBytesPerScan & 3;
 
 	if (accel->de_wait() != 0)
-		return -1;
+		return -EBUSY;
 
 	/*
 	 * 2D Source Base.
drivers/staging/sm750fb/sm750_hw.c +2 -2
index ce46f240cbaf..e4b6b254335e 100644
@@ -518,7 +518,7 @@ int hw_sm750le_de_wait(void)
 			return 0;
 	}
 	/* timeout error */
-	return -1;
+	return -ETIMEDOUT;
 }
 
 int hw_sm750_de_wait(void)
@@ -536,7 +536,7 @@ int hw_sm750_de_wait(void)
 			return 0;
 	}
 	/* timeout error */
-	return -1;
+	return -ETIMEDOUT;
 }
 
 int hw_sm750_pan_display(struct lynxfb_crtc *crtc,
Signature · 1 line
2.34.1
#1 lore raw

drivers/staging/sm750fb/ddk750_swi2c.c static long sw_i2c_write_byte(unsigned char data) · line 297

Quoted 10 lines · Soham Kute
drivers/staging/sm750fb/ddk750_swi2c.c +1 -1
index 0ef8d4ff2ef9..d90a93ab8fdc 100644
@@ -294,7 +294,7 @@ static long sw_i2c_write_byte(unsigned char data)
 	if (i < 0xff)
 		return 0;
 	else
-		return -1;
+		return -ETIMEDOUT;

The comment still says this returns -1.

Actually could you do this one function at a time, and in each commit message please say "The callers propogate the error code back" or " None of the callers check the error code" or "The callers treat all non-zero error codes as failure and return -EINVAL" or whatever.

drivers/staging/sm750fb/ddk750_swi2c.c int sm750_hw_copyarea(struct lynx_accel *accel, · line 266

Quoted 4 lines
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
@@ -264,7 +264,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel,
 		  (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */
 
 	if (accel->de_wait() != 0)

Did you consider propagating the error code from accel->de_wait() instead? That feels like a better solution but I haven't looked at it at all.

regards,
dan carpenter

author
#2 lore raw

v2 cover staging: sm750fb: fix error return values

This is v2 of the sm750fb error code fixes, split into one patch per function as requested by Dan Carpenter.

Changes in v2:
- Split into one patch per function
- Propagate de_wait() error instead of hardcoding -EBUSY
- Each commit message describes caller behavior

Soham Kute (6):
11ca38f0ec63 staging: sm750fb: hw_sm750le_de_wait: return -ETIMEDOUT on timeout 28df828cc89b staging: sm750fb: sm750_hw_fillrect: propagate de_wait() error 2378ece78154 staging: sm750fb: sm750_hw_copyarea: propagate de_wait() error 85139ac8c7fe staging: sm750fb: sm750_hw_imageblit: propagate de_wait() error 9c2430311e23 staging: sm750fb: sw_i2c_write_byte: return -ETIMEDOUT on timeout 915599b01e9b staging: sm750fb: sm750_sw_i2c_init: return -EINVAL for invalid GPIO

author
#3 lore raw

PATCH v2 1/6 staging: sm750fb: hw_sm750le_de_wait: return -ETIMEDOUT on timeout

Return -ETIMEDOUT instead of -1 when the DE engine poll loop times out. The callers check for non-zero return value and propagate the error code back to their callers.

---
 drivers/staging/sm750fb/sm750_hw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/sm750fb/sm750_hw.c +2 -2
index ce46f240cbaf..e4b6b254335e 100644
@@ -518,7 +518,7 @@ int hw_sm750le_de_wait(void)
 			return 0;
 	}
 	/* timeout error */
-	return -1;
+	return -ETIMEDOUT;
 }
 
 int hw_sm750_de_wait(void)
@@ -536,7 +536,7 @@ int hw_sm750_de_wait(void)
 			return 0;
 	}
 	/* timeout error */
-	return -1;
+	return -ETIMEDOUT;
 }
 
 int hw_sm750_pan_display(struct lynxfb_crtc *crtc,
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v2 2/6 staging: sm750fb: sm750_hw_fillrect: propagate de_wait() error

In reply to Soham Kute

Propagate the error from accel->de_wait() instead of returning -1. The caller treats all non-zero return values as failure.

---
 drivers/staging/sm750fb/sm750_accel.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/sm750fb/sm750_accel.c +4 -6
index 046b9282b24a..1bd0502db039 100644
@@ -90,14 +90,12 @@ int sm750_hw_fillrect(struct lynx_accel *accel,
 		      u32 color, u32 rop)
 {
 	u32 de_ctrl;
+	int ret;
 
-	if (accel->de_wait() != 0) {
-		/*
-		 * int time wait and always busy,seems hardware
-		 * got something error
-		 */
+	ret = accel->de_wait();
+	if (ret) {
 		pr_debug("De engine always busy\n");
-		return -1;
+		return ret;
 	}
 
 	write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH v2 3/6 staging: sm750fb: sm750_hw_copyarea: propagate de_wait() error

In reply to Soham Kute

Propagate the error from accel->de_wait() instead of returning -1. The caller treats all non-zero return values as failure.

---
 drivers/staging/sm750fb/sm750_accel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/sm750fb/sm750_accel.c +4 -2
index 1bd0502db039..f2fde011e7ca 100644
@@ -152,6 +152,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel,
 		      unsigned int rop2)
 {
 	unsigned int nDirection, de_ctrl;
+	int ret;
 
 	nDirection = LEFT_TO_RIGHT;
 	/* Direction of ROP2 operation: 1 = Left to Right, (-1) = Right to Left */
@@ -261,8 +262,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel,
 		   DE_WINDOW_WIDTH_DST_MASK) |
 		  (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */
 
-	if (accel->de_wait() != 0)
-		return -1;
+	ret = accel->de_wait();
+	if (ret)
+		return ret;
 
 	write_dpr(accel, DE_SOURCE,
 		  ((sx << DE_SOURCE_X_K1_SHIFT) & DE_SOURCE_X_K1_MASK) |
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 3/6] staging: sm750fb: sm750_hw_copyarea: propagate de_wait() error

Quoted 3 lines · Soham Kute

Propagate the error from accel->de_wait() instead of returning -1. The caller treats all non-zero return values as failure.

The caller just ignores errors.

regards,
dan carpenter

author
#7 lore raw

PATCH v2 4/6 staging: sm750fb: sm750_hw_imageblit: propagate de_wait() error

In reply to Soham Kute

Propagate the error from accel->de_wait() instead of returning -1. The caller treats all non-zero return values as failure.

---
 drivers/staging/sm750fb/sm750_accel.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/sm750fb/sm750_accel.c +4 -3
index f2fde011e7ca..7d11810864ae 100644
@@ -325,15 +325,16 @@ int sm750_hw_imageblit(struct lynx_accel *accel, const char *pSrcbuf,
 	unsigned int ulBytesRemain;
 	unsigned int de_ctrl = 0;
 	unsigned char ajRemain[4];
-	int i, j;
+	int i, j, ret;
 
 	startBit &= 7; /* Just make sure the start bit is within legal range */
 	ulBytesPerScan = (width + startBit + 7) / 8;
 	ul4BytesPerScan = ulBytesPerScan & ~3;
 	ulBytesRemain = ulBytesPerScan & 3;
 
-	if (accel->de_wait() != 0)
-		return -1;
+	ret = accel->de_wait();
+	if (ret)
+		return ret;
 
 	/*
 	 * 2D Source Base.
Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH 4/6] staging: sm750fb: sm750_hw_imageblit: propagate de_wait() error

Quoted 2 lines · Soham Kute

Propagate the error from accel->de_wait() instead of returning -1. The caller treats all non-zero return values as failure.

The caller ignores errors.

regards,
dan carpenter

author
#9 lore raw

PATCH v2 5/6 staging: sm750fb: sw_i2c_write_byte: return -ETIMEDOUT on timeout

In reply to Soham Kute

Return -ETIMEDOUT instead of -1 when the I2C byte write times out. The callers check for non-zero return value and treat it as failure.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/sm750fb/ddk750_swi2c.c +1 -1
index 0ef8d4ff2ef9..a17f758dda6c 100644
@@ -294,7 +294,7 @@ static long sw_i2c_write_byte(unsigned char data)
 	if (i < 0xff)
 		return 0;
 	else
-		return -1;
+		return -ETIMEDOUT;
 }
 
 /*
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH 5/6] staging: sm750fb: sw_i2c_write_byte: return -ETIMEDOUT on timeout

Quoted 3 lines · Soham Kute

Return -ETIMEDOUT instead of -1 when the I2C byte write times out. The callers check for non-zero return value and treat it as failure.

"The callers either ignore errors or treat all non-zero returns as failure and return -1."

drivers/staging/sm750fb/ddk750_swi2c.c static long sw_i2c_write_byte(unsigned char data)

Quoted 10 lines
---
 drivers/staging/sm750fb/ddk750_swi2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
index 0ef8d4ff2ef9..a17f758dda6c 100644
@@ -294,7 +294,7 @@ static long sw_i2c_write_byte(unsigned char data)

Need to update the comments at the start of the function as well.

234 /*

   235   *  This function writes one byte to the slave device
   236   *
   237   *  Parameters:
   238   *      data    - Data to be write to the slave device
   239   *
   240   *  Return Value:
   241   *       0   - Success
   242   *      -1   - Fail to write byte
                ^^^^^^^^^^^^^^^^^^^^^^^^^

243 */
244 static long sw_i2c_write_byte(unsigned char data)

drivers/staging/sm750fb/ddk750_swi2c.c static long sw_i2c_write_byte(unsigned char data) · line 297

Quoted 5 lines
drivers/staging/sm750fb/ddk750_swi2c.c +1 -1
 	if (i < 0xff)
 		return 0;
 	else
-		return -1;
+		return -ETIMEDOUT;

I don't think -ETIMEDOUT is the correct error code. Maybe -EIO or -EINVAL.

regards,
dan carpenter

author
#11 lore raw

PATCH v2 6/6 staging: sm750fb: sm750_sw_i2c_init: return -EINVAL for invalid GPIO

In reply to Soham Kute

Return -EINVAL instead of -1 when the GPIO pin number is out of range. The caller checks for non-zero return value as failure.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/sm750fb/ddk750_swi2c.c +1 -1
index a17f758dda6c..d90a93ab8fdc 100644
@@ -394,7 +394,7 @@ long sm750_sw_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
 	 * range is only from [0..63]
 	 */
 	if ((clk_gpio > 31) || (data_gpio > 31))
-		return -1;
+		return -EINVAL;
 
 	if (sm750_get_chip_type() == SM750LE)
 		return sm750le_i2c_init(clk_gpio, data_gpio);
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH 6/6] staging: sm750fb: sm750_sw_i2c_init: return -EINVAL for invalid GPIO

Quoted 3 lines · Soham Kute

Return -EINVAL instead of -1 when the GPIO pin number is out of range. The caller checks for non-zero return value as failure.

The caller ignores errors.

Quoted 10 lines
---
 drivers/staging/sm750fb/ddk750_swi2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
index a17f758dda6c..d90a93ab8fdc 100644

drivers/staging/sm750fb/ddk750_swi2c.c long sm750_sw_i2c_init(unsigned char clk_gpio, unsigned char data_gpio) · line 397

Quoted 5 lines
drivers/staging/sm750fb/ddk750_swi2c.c +1 -1
@@ -394,7 +394,7 @@ long sm750_sw_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
 	 * range is only from [0..63]
 	 */
 	if ((clk_gpio > 31) || (data_gpio > 31))
-		return -1;
+		return -EINVAL;

Need to update the comments for the function.

regards,
dan carpenter

Quoted 5 lines
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
 	if (sm750_get_chip_type() == SM750LE)
 		return sm750le_i2c_init(clk_gpio, data_gpio);
Signature · 1 line
2.34.1
author
#13 lore raw

PATCH v2 1/6 staging: sm750fb: hw_sm750le_de_wait: return -ETIMEDOUT on timeout

In reply to Dan Carpenter

Return -ETIMEDOUT instead of -1 when the DE engine poll loop times out. The callers check for non-zero return value and propagate the error code back to their callers.

---
 drivers/staging/sm750fb/sm750_hw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/sm750fb/sm750_hw.c +2 -2
index ce46f240cbaf..e4b6b254335e 100644
@@ -518,7 +518,7 @@ int hw_sm750le_de_wait(void)
 			return 0;
 	}
 	/* timeout error */
-	return -1;
+	return -ETIMEDOUT;
 }
 
 int hw_sm750_de_wait(void)
@@ -536,7 +536,7 @@ int hw_sm750_de_wait(void)
 			return 0;
 	}
 	/* timeout error */
-	return -1;
+	return -ETIMEDOUT;
 }
 
 int hw_sm750_pan_display(struct lynxfb_crtc *crtc,
Signature · 1 line
2.34.1
author
#14 lore raw

PATCH v2 2/6 staging: sm750fb: sm750_hw_fillrect: propagate de_wait() error

Propagate the error from accel->de_wait() instead of returning -1. The caller treats all non-zero return values as failure.

---
 drivers/staging/sm750fb/sm750_accel.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/sm750fb/sm750_accel.c +4 -6
index 046b9282b24a..1bd0502db039 100644
@@ -90,14 +90,12 @@ int sm750_hw_fillrect(struct lynx_accel *accel,
 		      u32 color, u32 rop)
 {
 	u32 de_ctrl;
+	int ret;
 
-	if (accel->de_wait() != 0) {
-		/*
-		 * int time wait and always busy,seems hardware
-		 * got something error
-		 */
+	ret = accel->de_wait();
+	if (ret) {
 		pr_debug("De engine always busy\n");
-		return -1;
+		return ret;
 	}
 
 	write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */
Signature · 1 line
2.34.1
#15 lore raw

Re: [PATCH 2/6] staging: sm750fb: sm750_hw_fillrect: propagate de_wait() error

Quoted 2 lines · Soham Kute

Propagate the error from accel->de_wait() instead of returning -1. The caller treats all non-zero return values as failure.

No, the caller just ignores the errors.

regards,
dan carpenter

author
#16 lore raw

PATCH v2 3/6 staging: sm750fb: sm750_hw_copyarea: propagate de_wait() error

In reply to Soham Kute

Propagate the error from accel->de_wait() instead of returning -1. The caller ignores the return value.

---
 drivers/staging/sm750fb/sm750_accel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/sm750fb/sm750_accel.c +4 -2
index 1bd0502db039..f2fde011e7ca 100644
@@ -152,6 +152,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel,
 		      unsigned int rop2)
 {
 	unsigned int nDirection, de_ctrl;
+	int ret;
 
 	nDirection = LEFT_TO_RIGHT;
 	/* Direction of ROP2 operation: 1 = Left to Right, (-1) = Right to Left */
@@ -261,8 +262,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel,
 		   DE_WINDOW_WIDTH_DST_MASK) |
 		  (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */
 
-	if (accel->de_wait() != 0)
-		return -1;
+	ret = accel->de_wait();
+	if (ret)
+		return ret;
 
 	write_dpr(accel, DE_SOURCE,
 		  ((sx << DE_SOURCE_X_K1_SHIFT) & DE_SOURCE_X_K1_MASK) |
Signature · 1 line
2.34.1
author
#17 lore raw

PATCH v2 4/6 staging: sm750fb: sm750_hw_imageblit: propagate de_wait() error

In reply to Soham Kute

Propagate the error from accel->de_wait() instead of returning -1. The caller ignores the return value.

---
 drivers/staging/sm750fb/sm750_accel.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/sm750fb/sm750_accel.c +4 -3
index f2fde011e7ca..7d11810864ae 100644
@@ -325,15 +325,16 @@ int sm750_hw_imageblit(struct lynx_accel *accel, const char *pSrcbuf,
 	unsigned int ulBytesRemain;
 	unsigned int de_ctrl = 0;
 	unsigned char ajRemain[4];
-	int i, j;
+	int i, j, ret;
 
 	startBit &= 7; /* Just make sure the start bit is within legal range */
 	ulBytesPerScan = (width + startBit + 7) / 8;
 	ul4BytesPerScan = ulBytesPerScan & ~3;
 	ulBytesRemain = ulBytesPerScan & 3;
 
-	if (accel->de_wait() != 0)
-		return -1;
+	ret = accel->de_wait();
+	if (ret)
+		return ret;
 
 	/*
 	 * 2D Source Base.
Signature · 1 line
2.34.1
author
#18 lore raw

PATCH v2 5/6 staging: sm750fb: sw_i2c_write_byte: return -EIO on failure

In reply to Soham Kute

Return -EIO instead of -1 when the I2C byte write fails. The caller ignores the return value.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +2 -2
index 0ef8d4ff2ef9..c73943341f66 100644
@@ -239,7 +239,7 @@ static void sw_i2c_stop(void)
  *
  *  Return Value:
  *       0   - Success
- *      -1   - Fail to write byte
+ *      -EIO - Fail to write byte
  */
 static long sw_i2c_write_byte(unsigned char data)
 {
@@ -294,7 +294,7 @@ static long sw_i2c_write_byte(unsigned char data)
 	if (i < 0xff)
 		return 0;
 	else
-		return -1;
+		return -EIO;
 }
 
 /*
Signature · 1 line
2.34.1
author
#19 lore raw

PATCH v2 6/6 staging: sm750fb: sm750_sw_i2c_init: return -EINVAL for invalid GPIO

In reply to Soham Kute

Return -EINVAL instead of -1 when the GPIO pin number is out of range. The caller ignores the return value.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +3 -3
index c73943341f66..46599be8d6b9 100644
@@ -344,7 +344,7 @@ static unsigned char sw_i2c_read_byte(unsigned char ack)
  *      data_gpio     - The GPIO pin to be used as i2c SDA
  *
  * Return Value:
- *      -1   - Fail to initialize the i2c
+ *      -EINVAL - Fail to initialize the i2c
  *       0   - Success
  */
 static long sm750le_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
@@ -382,7 +382,7 @@ static long sm750le_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
  *      data_gpio     - The GPIO pin to be used as i2c SDA
  *
  * Return Value:
- *      -1   - Fail to initialize the i2c
+ *      -EINVAL - Fail to initialize the i2c
  *       0   - Success
  */
 long sm750_sw_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
@@ -394,7 +394,7 @@ long sm750_sw_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
 	 * range is only from [0..63]
 	 */
 	if ((clk_gpio > 31) || (data_gpio > 31))
-		return -1;
+		return -EINVAL;
 
 	if (sm750_get_chip_type() == SM750LE)
 		return sm750le_i2c_init(clk_gpio, data_gpio);
Signature · 1 line
2.34.1
#20 lore raw

Re: [PATCH 6/6] staging: sm750fb: sm750_sw_i2c_init: return -EINVAL for invalid GPIO

Quoted 13 lines · Soham Kute

Return -EINVAL instead of -1 when the GPIO pin number is out of range. The caller ignores the return value.

---
 drivers/staging/sm750fb/ddk750_swi2c.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/sm750fb/ddk750_swi2c.c +0 -0
index c73943341f66..46599be8d6b9 100644

drivers/staging/sm750fb/ddk750_swi2c.c static unsigned char sw_i2c_read_byte(unsigned char ack) · line 350

Quoted 8 lines
drivers/staging/sm750fb/ddk750_swi2c.c +1 -1
@@ -344,7 +344,7 @@ static unsigned char sw_i2c_read_byte(unsigned char ack)
  *      data_gpio     - The GPIO pin to be used as i2c SDA
  *
  * Return Value:
- *      -1   - Fail to initialize the i2c
+ *      -EINVAL - Fail to initialize the i2c
  *       0   - Success
  */
 static long sm750le_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)

This part needs to be done in the patch that changes sw_i2c_read_byte().

regards,
dan carpenter

Quoted 21 lines
drivers/staging/sm750fb/ddk750_swi2c.c +2 -2
@@ -382,7 +382,7 @@ static long sm750le_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
  *      data_gpio     - The GPIO pin to be used as i2c SDA
  *
  * Return Value:
- *      -1   - Fail to initialize the i2c
+ *      -EINVAL - Fail to initialize the i2c
  *       0   - Success
  */
 long sm750_sw_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
@@ -394,7 +394,7 @@ long sm750_sw_i2c_init(unsigned char clk_gpio, unsigned char data_gpio)
 	 * range is only from [0..63]
 	 */
 	if ((clk_gpio > 31) || (data_gpio > 31))
-		return -1;
+		return -EINVAL;
 
 	if (sm750_get_chip_type() == SM750LE)
 		return sm750le_i2c_init(clk_gpio, data_gpio);
Signature · 1 line
2.34.1
#21 lore raw

Re: [PATCH 1/6] staging: sm750fb: hw_sm750le_de_wait: return -ETIMEDOUT on timeout

In reply to Soham Kute
Quoted 4 lines · Soham Kute

Return -ETIMEDOUT instead of -1 when the DE engine poll loop times out. The callers check for non-zero return value and propagate the error code back to their callers.

They don't propagate the error back. The callers do:

drivers/staging/sm750fb/sm750_accel.c
87 int sm750_hw_fillrect(struct lynx_accel *accel,
88 u32 base, u32 pitch, u32 Bpp,
89 u32 x, u32 y, u32 width, u32 height,
90 u32 color, u32 rop)
91 {
92 u32 de_ctrl;
93
94 if (accel->de_wait() != 0) {
95 /*
96 * int time wait and always busy,seems hardware
97 * got something error
98 */
99 pr_debug("De engine always busy\n");
100 return -1;
101 }

They return -1. Propagating the errors means:

	ret = accel->de_wait();
	if (ret)
		return ret;

Also this is a v3 patch, it needs v3 in the subject and a little description of what changed.

https://staticthinking.wordpress.com/2022/07/27/how-to-send-a-v2-patch/

regards,
dan carpenter