Skip to contentSkip to conversation

staging: keucr: Use memcmp() instaed of custom StringCmp() and some style cleanups

PATCH In review Javier Martinez Canillas 3 participants 3 messages Dec 31, 2010 – Jan 1, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 staging: keucr: Use memcmp() instaed of custom StringCmp() and some style cleanups

---
 drivers/staging/keucr/smilsub.c |   65 ++++++++++++++++++++------------------
 1 files changed, 34 insertions(+), 31 deletions(-)
drivers/staging/keucr/smilsub.c +34 -31
index ce10cf2..8256fad 100644
@@ -1482,54 +1482,57 @@ BYTE _Check_D_DevCode(BYTE dcode)
 //----- Check_D_ReadError() ----------------------------------------------
 int Check_D_ReadError(BYTE *redundant)
 {
-    // Driver 不做 ECC Check
-    return(SUCCESS);
-    if (!StringCmp((char *)(redundant+0x0D),(char *)EccBuf,3))
-        if (!StringCmp((char *)(redundant+0x08),(char *)(EccBuf+0x03),3))
-            return(SUCCESS);
+	/* Driver ECC Check */
+	return SUCCESS;
+	if (!memcmp(redundant+0x0D, EccBuf, 3))
+		if (!memcmp(redundant+0x08, EccBuf+0x03, 3))
+			return SUCCESS;
 
-    return(ERROR);
+	return ERROR;
 }
 
 //----- Check_D_Correct() ----------------------------------------------
 int Check_D_Correct(BYTE *buf,BYTE *redundant)
 {
-    // Driver 不做 ECC Check
-    return(SUCCESS);
-    if (StringCmp((char *)(redundant+0x0D),(char *)EccBuf,3))
-        if (_Correct_D_SwECC(buf,redundant+0x0D,EccBuf))
-            return(ERROR);
-
-    buf+=0x100;
-    if (StringCmp((char *)(redundant+0x08),(char *)(EccBuf+0x03),3))
-        if (_Correct_D_SwECC(buf,redundant+0x08,EccBuf+0x03))
-            return(ERROR);
-
-    return(SUCCESS);
+	/* Driver ECC Check */
+	return SUCCESS;
+	if (memcmp(redundant+0x0D, EccBuf, 3))
+		if (_Correct_D_SwECC(buf, redundant+0x0D, EccBuf))
+			return ERROR;
+
+	buf += 0x100;
+	if (memcmp(redundant+0x08, EccBuf+0x03, 3))
+		if (_Correct_D_SwECC(buf, redundant+0x08, EccBuf+0x03))
+			return ERROR;
+
+	return SUCCESS;
 }
 
 //----- Check_D_CISdata() ----------------------------------------------
 int Check_D_CISdata(BYTE *buf, BYTE *redundant)
 {
-    BYTE cis[]={0x01,0x03,0xD9,0x01,0xFF,0x18,0x02,0xDF,0x01,0x20};
+	BYTE cis[] = {0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02,
+		      0xDF, 0x01, 0x20};
+
+	int cis_len = sizeof(cis);
 
-    if (!IsSSFDCCompliance && !IsXDCompliance)
-        return(SUCCESS);             // 目前為強制 SUCCESS [Arnold 02-08-23] SSFDC 測試, 不能強制 SUCCESS
+	if (!IsSSFDCCompliance && !IsXDCompliance)
+		return SUCCESS;
 
-    if (!StringCmp((char *)(redundant+0x0D),(char *)EccBuf,3))
-        return(StringCmp((char *)buf,(char *)cis,10));
+	if (!memcmp(redundant+0x0D, EccBuf, 3))
+		return memcmp(buf, cis, cis_len);
 
-    if (!_Correct_D_SwECC(buf,redundant+0x0D,EccBuf))
-        return(StringCmp((char *)buf,(char *)cis,10));
+	if (!_Correct_D_SwECC(buf, redundant+0x0D, EccBuf))
+		return memcmp(buf, cis, cis_len);
 
-    buf+=0x100;
-    if (!StringCmp((char *)(redundant+0x08),(char *)(EccBuf+0x03),3))
-        return(StringCmp((char *)buf,(char *)cis,10));
+	buf += 0x100;
+	if (!memcmp(redundant+0x08, EccBuf+0x03, 3))
+		return memcmp(buf, cis, cis_len);
 
-    if (!_Correct_D_SwECC(buf,redundant+0x08,EccBuf+0x03))
-        return(StringCmp((char *)buf,(char *)cis,10));
+	if (!_Correct_D_SwECC(buf, redundant+0x08, EccBuf+0x03))
+		return memcmp(buf, cis, cis_len);
 
-    return(ERROR);
+	return ERROR;
 }
 
 //----- Set_D_RightECC() ----------------------------------------------
Signature · 6 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

Re: [PATCH 1/2] staging: keucr: Use memcmp() instaed of custom

Quoted 1 line · Javier Martinez Canillas

Hi Javier.

drivers/staging/keucr/smilsub.c

Quoted 1 line
drivers/staging/keucr/smilsub.c +0 -0

[]

drivers/staging/keucr/smilsub.c BYTE _Check_D_DevCode(BYTE dcode) · line 1489

Quoted 12 lines

int Check_D_ReadError(BYTE *redundant)
{

drivers/staging/keucr/smilsub.c +5 -5
-    // Driver 䣰 ECC Check
-    return(SUCCESS);
-    if (!StringCmp((char *)(redundant+0x0D),(char *)EccBuf,3))
-        if (!StringCmp((char *)(redundant+0x08),(char *)(EccBuf+0x03),3))
-            return(SUCCESS);
+	/* Driver ECC Check */
+	return SUCCESS;
+	if (!memcmp(redundant+0x0D, EccBuf, 3))
+		if (!memcmp(redundant+0x08, EccBuf+0x03, 3))
+			return SUCCESS;

Generally, it's better to have success at the end of a function and either a goto error or return error for error conditions.

Something like:

	if (!(!memcmp(redundant+0x0D, EccBuf, 3) &&
	      !memcmp(redundant+0x08, EccBuf+0x03, 3)))
		return ERROR;

	return SUCCESS;
Quoted 9 lines

int Check_D_Correct(BYTE *buf,BYTE *redundant)
{

drivers/staging/keucr/smilsub.c +0 -7
-    // Driver 䣰 ECC Check
-    return(SUCCESS);
-    if (StringCmp((char *)(redundant+0x0D),(char *)EccBuf,3))
-        if (_Correct_D_SwECC(buf,redundant+0x0D,EccBuf))
-            return(ERROR);
-
-    buf+=0x100;

drivers/staging/keucr/smilsub.c BYTE _Check_D_DevCode(BYTE dcode) · line 1501

Quoted 10 lines
drivers/staging/keucr/smilsub.c +5 -5
-    if (StringCmp((char *)(redundant+0x08),(char *)(EccBuf+0x03),3))
-        if (_Correct_D_SwECC(buf,redundant+0x08,EccBuf+0x03))
-            return(ERROR);
-
-    return(SUCCESS);
+	/* Driver ECC Check */
+	return SUCCESS;
+	if (memcmp(redundant+0x0D, EccBuf, 3))
+		if (_Correct_D_SwECC(buf, redundant+0x0D, EccBuf))
+			return ERROR;

You might as well take out useless code after returns instead of just changing function names.

If you keep it you should reformat it.

	if (memcmp(redundant+0x0D, EccBuf, 3) &&
	    _Correct_D_SwECC(buf, redundant+0x0D, EccBuf))
		return ERROR;

etc...

#2 lore raw

Re: [PATCH 1/2] staging: keucr: Use memcmp() instaed of custom

In reply to Javier Martinez Canillas
Quoted 3 lines · Joe Perches

On Fri, 2010-12-31 at 20:28 +0100, Javier Martinez Canillas wrote:

	if (!(!memcmp(redundant+0x0D, EccBuf, 3) &&
	      !memcmp(redundant+0x08, EccBuf+0x03, 3)))
                              ^^^          ^^^

Also we should add spaces around the '+' character. But this is dead code anyway so let's just merge it.

regards,
dan carpenter