OMAP: DSS2: Replace strncmp() with sysfs_streq() in overlay_manager_store()
PATCH RESEND 1/1 OMAP: DSS2: Replace strncmp() with sysfs_streq() in overlay_manager_store()
In the function overlay_manager_store, the length of the string buf is used to comapre the 2 strings, there is a possibility of false positive match if buf is a prefix string of another manager.
The use of sysfs_streq() fixes this.
--- drivers/video/omap2/dss/overlay.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/video/omap2/dss/overlay.c +1 -1
@@ -65,7 +65,7 @@ static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf,for (i =0 ; i <omap_dss_get_num_overlay_managers (); ++i) { mgr =omap_dss_get_overlay_manager (i); -if (strncmp (buf, mgr->name, len) ==0 ) +if (sysfs_streq (buf, mgr->name))break ; mgr =NULL ;
Signature · 1 line
1.5.4.7
Quoted 26 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Taneja, Archit
Sent: Wednesday, July 28, 2010 11:52 AM
To: [email protected]
Cc: [email protected]; Taneja, Archit
Subject: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()In the function
overlay_manager_store, the length of the string buf is used to comapre the 2 strings, there is a possibility of false positive match if buf is a prefix string of another manager.The use of
sysfs_streq()fixes this.Signed-off-by Archit Taneja <[email protected]>--- drivers/video/omap2/dss/overlay.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/video/omap2/dss/overlay.c +0
-0
drivers/video/omap2/dss/overlay.c static ssize_t overlay_manager_store(struct · line 70
Quoted 7 lines
drivers/video/omap2/dss/overlay.c +1
-1@@ -65,7 +65,7 @@ static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { mgr =omap_dss_get_overlay_manager (i); -if (strncmp (buf, mgr->name, len) ==0 ) +if (sysfs_streq (buf, mgr->name))
[sp] sysfs_streq() ignores trailing newlines during comparison. So,
the possibility mentioned in the description still stays.
I am not familiar with overall context; but wouldn't srtcmp() be the right choice? unless, of course, either of strings being compared are not null terminated.
Quoted 12 lines
drivers/video/omap2/dss/overlay.c +0
-0break ;mgr = NULL;
Signature · 7 lines
1.5.4.7 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 43 lines
-----Original Message-----
From: Premi, Sanjeev
Sent: Wednesday, July 28, 2010 7:28 PM
To: Taneja, Archit; [email protected]
Cc: [email protected]
Subject: RE: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()Quoted 3 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf OfTaneja, Archit
Quoted 7 lines
Sent: Wednesday, July 28, 2010 11:52 AM
To: [email protected]
Cc: [email protected]; Taneja, Archit
Subject: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()In the function
overlay_manager_store, the length of thestring buf is
Quoted 21 lines
used to comapre the 2 strings, there is a possibility of false positive match if buf is a prefix string of another manager.
The use of
sysfs_streq()fixes this.Signed-off-by Archit Taneja <[email protected]>--- drivers/video/omap2/dss/overlay.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/video/omap2/dss/overlay.c +0
-0@@ -65,7 +65,7 @@ static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { mgr =omap_dss_get_overlay_manager (i);
Quoted 5 lines
drivers/video/omap2/dss/overlay.c static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, · line 68
Quoted 2 lines
drivers/video/omap2/dss/overlay.c +1
-1-if (strncmp (buf, mgr->name, len) ==0 ) +if (sysfs_streq (buf, mgr->name))[sp]
sysfs_streq()ignores trailing newlines during comparison. So,
the possibility mentioned in the description still stays.
The aim is to compare one string which is a sysfs input and the other which is in the kernel.
Quoted 4 lines
I am not familiar with overall context; but wouldn't
srtcmp()be the right choice? unless, of course, either of strings being compared are not null terminated.
The sysfs input will have a newline and null at the end whereas the other string will only have null, strcmp will fail when we want the two strings to match.
Eg. Sysfs input "lcd\n\0"
Kernel string "lcd\0"
strcmp will fail here
Quoted 14 lines
Quoted 9 lines
drivers/video/omap2/dss/overlay.c +0
-0break ;mgr = NULL;
--
1.5.4.7--
To unsubscribe from this list: send the line "unsubscribelinux-omap"
Quoted 1 line
in the body of a message to [email protected] More
majordomo
Quoted 2 lines
Quoted 72 lines
-----Original Message-----
From: Taneja, Archit
Sent: Wednesday, July 28, 2010 8:06 PM
To: Premi, Sanjeev; [email protected]
Cc: [email protected]
Subject: RE: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()Quoted 41 lines
-----Original Message-----
From: Premi, Sanjeev
Sent: Wednesday, July 28, 2010 7:28 PM
To: Taneja, Archit; [email protected]
Cc: [email protected]
Subject: RE: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()Quoted 3 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf OfTaneja, Archit
Quoted 7 lines
Sent: Wednesday, July 28, 2010 11:52 AM
To: [email protected]
Cc: [email protected]; Taneja, Archit
Subject: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()In the function
overlay_manager_store, the length of thestring buf is
Quoted 21 lines
used to comapre the 2 strings, there is a possibility of false positive match if buf is a prefix string of another manager.
The use of
sysfs_streq()fixes this.Signed-off-by Archit Taneja <[email protected]>--- drivers/video/omap2/dss/overlay.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/video/omap2/dss/overlay.c +0
-0@@ -65,7 +65,7 @@ static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { mgr =omap_dss_get_overlay_manager (i);Quoted 5 lines
drivers/video/omap2/dss/overlay.c static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, · line 68
Quoted 2 lines
drivers/video/omap2/dss/overlay.c +1
-1-if (strncmp (buf, mgr->name, len) ==0 ) +if (sysfs_streq (buf, mgr->name))[sp]
sysfs_streq()ignores trailing newlines during comparison. So,
the possibility mentioned in the description still stays.The aim is to compare one string which is a sysfs input and the other which is in the kernel.
Quoted 4 lines
I am not familiar with overall context; but wouldn't
srtcmp()be the right choice? unless, of course, either of strings being compared are not null terminated.The sysfs input will have a newline and null at the end whereas the other string will only have null, strcmp will fail when we want the two
strings to match.
Quoted 4 lines
Eg. Sysfs input "lcd\n\0"
Kernel string "lcd\0"strcmp will fail here
[sp] If the patch is intending to fix this condition, then it isn't
evident from the description. You should consider updating the description.
Quoted 15 lines
Quoted 15 lines
Quoted 10 lines
drivers/video/omap2/dss/overlay.c +0
-0break ;mgr = NULL;
--
1.5.4.7--
To unsubscribe from this list: send the line "unsubscribelinux-omap"
Quoted 1 line
in the body of a message to [email protected] More
majordomo
Quoted 2 lines
Quoted 54 lines
Quoted 34 lines
Quoted 34 lines
Quoted 4 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf OfTaneja, Archit
Quoted 7 lines
Sent: Wednesday, July 28, 2010 11:52 AM
To: [email protected]
Cc: [email protected]; Taneja, Archit
Subject: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()In the function
overlay_manager_store, the length of thestring buf is
Quoted 21 lines
used to comapre the 2 strings, there is a possibility of false positive match if buf is a prefix string of another manager.
The use of
sysfs_streq()fixes this.Signed-off-by Archit Taneja <[email protected]>--- drivers/video/omap2/dss/overlay.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/video/omap2/dss/overlay.c +0
-0@@ -65,7 +65,7 @@ static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { mgr =omap_dss_get_overlay_manager (i);Quoted 4 lines
Quoted 4 lines
drivers/video/omap2/dss/overlay.c static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, · line 68
Quoted 2 lines
drivers/video/omap2/dss/overlay.c +1
-1-if (strncmp (buf, mgr->name, len) ==0 ) +if (sysfs_streq (buf, mgr->name))[sp]
sysfs_streq()ignores trailing newlines duringcomparison. So,
Quoted 3 lines
Quoted 1 line
the possibility mentioned in the description still stays.
The aim is to compare one string which is a sysfs input and
the other
Quoted 11 lines
which is in the kernel.
Quoted 4 lines
I am not familiar with overall context; but wouldn't
srtcmp()be the right choice? unless, of course, either of strings being compared are not null terminated.The sysfs input will have a newline and null at the end whereas the other string will only have null, strcmp will fail when we want the two strings to match.
Quoted 8 lines
Quoted 4 lines
Eg. Sysfs input "lcd\n\0"
Kernel string "lcd\0"strcmp will fail here
[sp] If the patch is intending to fix this condition, then it isn't
evident from the description. You should consider updating the description.
The patch isn't intending to fix this condition, this condition doesn't occur at all in the existing code. I explained this to tell you why strcmp is a bad choice, the patch description tells why sysfs_streq is a better choice over strncmp.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
drivers/video/omap2/dss/overlay.c +0
-0break ;mgr = NULL;
--
1.5.4.7--
To unsubscribe from this list: send the line "unsubscribelinux-omap"
Quoted 1 line
in the body of a message to [email protected] More
majordomo
Quoted 2 lines
Quoted 75 lines
-----Original Message-----
From: Taneja, Archit
Sent: Thursday, July 29, 2010 9:16 AM
To: Premi, Sanjeev; [email protected]
Cc: [email protected]
Subject: RE: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf OfTaneja, Archit
Quoted 6 lines
Sent: Wednesday, July 28, 2010 11:52 AM
To: [email protected]
Cc: [email protected]; Taneja, Archit
Subject: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
In the function
overlay_manager_store, the length of thestring buf is
Quoted 1 line
used to comapre the 2 strings, there is a possibility
of false
Quoted 24 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
positive match if buf is a prefix string of another manager.
The use of
sysfs_streq()fixes this.Signed-off-by Archit Taneja <[email protected]>--- drivers/video/omap2/dss/overlay.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/video/omap2/dss/overlay.c +0
-0@@ -65,7 +65,7 @@ static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { mgr =omap_dss_get_overlay_manager (i);Quoted 4 lines
Quoted 4 lines
drivers/video/omap2/dss/overlay.c static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, · line 68
Quoted 2 lines
drivers/video/omap2/dss/overlay.c +1
-1-if (strncmp (buf, mgr->name, len) ==0 ) +if (sysfs_streq (buf, mgr->name))[sp]
sysfs_streq()ignores trailing newlines duringQuoted 9 lines
comparison. So,
Quoted 3 lines
Quoted 1 line
the possibility mentioned in the description still stays.
The aim is to compare one string which is a sysfs input and
the other
Quoted 4 lines
which is in the kernel.
Quoted 2 lines
I am not familiar with overall context; but
wouldn't
srtcmp()Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
be the right choice? unless, of course, either of strings being compared are not null terminated.
The sysfs input will have a newline and null at the end
whereas the
Quoted 1 line
Quoted 1 line
other string will only have null, strcmp will fail when
we want the
Quoted 10 lines
Quoted 6 lines
two strings to match.
Eg. Sysfs input "lcd\n\0"
Kernel string "lcd\0"strcmp will fail here
[sp] If the patch is intending to fix this condition, then it isn't
evident from the description. You should consider updating the description.
Quoted 7 lines
The patch isn't intending to fix this condition, this condition doesn't
occur at all in the existing code. I explained this to tell you why strcmp
is a bad choice, the patch description tells whysysfs_streqis a better
choice over strncmp.
[sp] Can you explain the real condition and how/why it can't be handled
by strcmp()
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 6 lines
drivers/video/omap2/dss/overlay.c +0
-0break ;Quoted 6 lines
mgr = NULL;
--
1.5.4.7--
To unsubscribe from this list: send the line "unsubscribelinux-omap"
Quoted 1 line
in the body of a message to [email protected] More
majordomo
Quoted 2 lines
Quoted 70 lines
Quoted 24 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf OfTaneja, Archit
Quoted 6 lines
Sent: Wednesday, July 28, 2010 11:52 AM
To: [email protected]
Cc: [email protected]; Taneja, Archit
Subject: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
In the function
overlay_manager_store, the length of thestring buf is
Quoted 1 line
used to comapre the 2 strings, there is a possibility
of false
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
positive match if buf is a prefix string of another manager.
The use of
sysfs_streq()fixes this.Signed-off-by Archit Taneja <[email protected]>--- drivers/video/omap2/dss/overlay.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/video/omap2/dss/overlay.c static ssize_t
Quoted 6 lines
drivers/video/omap2/dss/overlay.c +0
-0@@ -65,7 +65,7 @@ static ssize_toverlay_manager_store(struct
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/video/omap2/dss/overlay.c static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, · line 68
Quoted 7 lines
drivers/video/omap2/dss/overlay.c +1
-1omap_overlay *ovl, const char *buf, for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { mgr =omap_dss_get_overlay_manager (i); -if (strncmp (buf, mgr->name, len) ==0 ) +if (sysfs_streq (buf, mgr->name))[sp]
sysfs_streq()ignores trailing newlines duringQuoted 9 lines
comparison. So,
Quoted 3 lines
Quoted 1 line
the possibility mentioned in the description still stays.
The aim is to compare one string which is a sysfs input and
the other
Quoted 4 lines
which is in the kernel.
Quoted 2 lines
I am not familiar with overall context; but
Quoted 16 lines
wouldn't
srtcmp()Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
be the right choice? unless, of course, either of strings being compared are not null terminated.
The sysfs input will have a newline and null at the end
whereas the
Quoted 1 line
Quoted 1 line
other string will only have null, strcmp will fail when
we want the
Quoted 8 lines
Quoted 6 lines
two strings to match.
Eg. Sysfs input "lcd\n\0"
Kernel string "lcd\0"strcmp will fail here
[sp] If the patch is intending to fix this condition,
then it isn't
Quoted 1 line
Quoted 1 line
evident from the description. You should consider
updating the
Quoted 2 lines
Quoted 1 line
description.
Quoted 8 lines
Quoted 4 lines
The patch isn't intending to fix this condition, this condition doesn't occur at all in the existing code. I explained this to tell you why strcmp is a bad choice, the patch description tells why
sysfs_streqis a better choice over strncmp.[sp] Can you explain the real condition and how/why it can't be handled
bystrcmp()
Okay, the real condition (why this patch was sent) is this (please have a look at the whole function body while reading the explanation):
The user enters "lcd" via sysfs input to change the overlay's manager to "lcd", this input will be converted to "lcd\n\0", the function will try to comapre this name with all the existing managers names. Consider the case where buf (sysfs input) is "lcd\n\0" and mgr->name is "lcd2\0".
Now, len is calculated as 3 and is passed as the parameter to stncmp, in this case, "lcd" and "lcd2" will match because only the first 3 characters are compared. This is what I meant by buf being a prefix string of mgr->name.
This above is the condition which the patch tries to resolve.
strcmp will work like a charm here and ignore false positives, but it will generate a false negative which didn't occur previously at all, an example:
If buf is "lcd\n\0" and mgr->name is "lcd\0" the code should match this, but strcmp won't.
Hence, to prevent both false positives and false negatives sysfs_streq is used.
If you want to use strcmp, you will have to manually strip off the newlines.
I have also shared the patch link below which intrioduces sysfs_streq in the kernel and explains why it has been introduced in the first place:
http://kerneltrap.org/mailarchive/git-commits-head/2008/5/1/1688084
I hope this explanation elaborates things clearly.
Thanks,
Archit
Quoted 10 lines
-----Original Message-----
From: Taneja, Archit
Sent: Thursday, July 29, 2010 11:27 AM
To: Premi, Sanjeev; [email protected]
Cc: [email protected]
Subject: RE: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()
[snip]...[snip]
Quoted 62 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
[sp]
sysfs_streq()ignores trailing newlines duringcomparison. So,
Quoted 1 line
Quoted 1 line
the possibility mentioned in the description
still stays.
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
The aim is to compare one string which is a sysfs input and
the other
Quoted 4 lines
which is in the kernel.
Quoted 2 lines
I am not familiar with overall context; but
wouldn't
srtcmp()Quoted 1 line
Quoted 1 line
Quoted 1 line
be the right choice? unless, of course, either
of strings
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
being compared are not null terminated.
The sysfs input will have a newline and null at the end
whereas the
Quoted 1 line
Quoted 1 line
other string will only have null, strcmp will fail when
we want the
Quoted 5 lines
Quoted 5 lines
two strings to match.
Eg. Sysfs input "lcd\n\0"
Kernel string "lcd\0"Quoted 10 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
strcmp will fail here
[sp] If the patch is intending to fix this condition,
then it isn't
Quoted 1 line
Quoted 1 line
evident from the description. You should consider
updating the
Quoted 4 lines
Quoted 1 line
description.
The patch isn't intending to fix this condition, this condition doesn't occur at all in the existing code. I explained
this to tell
Quoted 6 lines
Quoted 2 lines
you why strcmp is a bad choice, the patch description tells why
sysfs_streqis a better choice over strncmp.[sp] Can you explain the real condition and how/why it can't be handled
bystrcmp()Okay, the real condition (why this patch was sent) is this (please have a look
at the whole function body while reading the explanation):The user enters "lcd" via sysfs input to change the overlay's manager to "lcd",
this input will be converted to "lcd\n\0", the function will try to comapre this name with all the existing managers names. Consider the case where
buf (sysfs input) is "lcd\n\0" andmgr->nameis "lcd2\0".Now, len is calculated as 3 and is passed as the parameter to stncmp, in this
case, "lcd" and "lcd2" will match because only the first 3 characters are compared.
This is what I meant by buf being a prefix string ofmgr->name.This above is the condition which the patch tries to resolve.
Quoted 8 lines
strcmp will work like a charm here and ignore false positives, but it will generate
a false negative which didn't occur previously at all, an example:If buf is "lcd\n\0" and
mgr->nameis "lcd\0" the code should match this, but strcmp
won't.
[sp] This explains. And my earlier comment was to update the
description with need for change. I believe quick summary the discussion above will be good for the patch.
Quoted 12 lines
Hence, to prevent both false positives and false negatives
sysfs_streqis used.If you want to use strcmp, you will have to manually strip off the newlines.
I have also shared the patch link below which intrioduces
sysfs_streqin the kernel
and explains why it has been introduced in the first place:http://kerneltrap.org/mailarchive/git-commits-head/2008/5/1/1688084
[sp] I am aware of it. See my first comment.
Quoted 6 lines
I hope this explanation elaborates things clearly.
Thanks,
Archit
[snip]
Quoted 6 lines
Quoted 1 line
[sp] This explains. And my earlier comment was to update the
description with need for change. I believe quick summary the discussion above will be good for the patch.
Okay, will do. But what am is supposed to add more in the summary? Should I add how sysfs_streq is a better choice over strcmp? Or should I emphasize more how the false positive scenario can occur with strncmp?
Thanks,
Archit
Quoted 17 lines
-----Original Message-----
From: Taneja, Archit
Sent: Thursday, July 29, 2010 4:40 PM
To: Premi, Sanjeev; [email protected]
Cc: [email protected]
Subject: RE: [PATCH resend] OMAP: DSS2: Replacestrncmp()withsysfs_streq()inoverlay_manager_store()[snip]
Quoted 6 lines
Quoted 1 line
[sp] This explains. And my earlier comment was to update the
description with need for change. I believe quick summary the discussion above will be good for the patch.
Quoted 4 lines
Okay, will do. But what am is supposed to add more in the summary? Should I add how
sysfs_streqis a better choice over strcmp? Or should I emphasize more how the false positive scenario can occur with strncmp?
I believe it should indicate problem being fixed. sysfs_streq() vs strncmp() is means of arriving at solution.
Quoted 4 lines
Thanks,
Archit