Skip to contentSkip to conversation

ASoC: core: No need to use strncmp()

PATCH In review Dimitris Papastamos 2 participants 6 messages Jul 31, 2013

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

PATCH 1/1 ASoC: core: No need to use strncmp()

---
 sound/soc/soc-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/soc-core.c +2 -2
index d68a486..9f60894 100644
@@ -2309,7 +2309,7 @@ struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
 		return NULL;
 
 	list_for_each_entry(kctl, &card->controls, list)
-		if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name)))
+		if (!strcmp(kctl->id.name, name))
 			return kctl;
 	return NULL;
 }
@@ -3056,7 +3056,7 @@ int snd_soc_limit_volume(struct snd_soc_codec *codec,
 		return -EINVAL;
 
 	list_for_each_entry(kctl, &card->controls, list) {
-		if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
+		if (!strcmp(kctl->id.name, name)) {
 			found = 1;
 			break;
 		}
Signature · 1 line
1.8.3.4
maintainer
#3 lore raw
Quoted 8 lines · Dimitris Papastamos
Quoted 4 lines · Mark Brown
Quoted 1 line · Dimitris Papastamos

Why?

Hm, strncmp() suggests that we might not care about the entire string. Although trivial, I thought strcmp() is clearer in this context.

One of the reasons we use strncmp() here is to avoid going beyond the end of the fixed size buffer.

#4 lore raw
Quoted 5 lines · Mark Brown
Quoted 3 lines · Dimitris Papastamos
Quoted 2 lines · Mark Brown
Quoted 1 line · Dimitris Papastamos
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Why?

Hm, strncmp() suggests that we might not care about the entire string. Although trivial, I thought strcmp() is clearer in this context.

One of the reasons we use strncmp() here is to avoid going beyond the end of the fixed size buffer.

Right, surely though the kcontrol names are always null terminated? In any case, looks more safe to strncmp().

maintainer
#5 lore raw
Quoted 7 lines · Dimitris Papastamos
Quoted 2 lines · Mark Brown

One of the reasons we use strncmp() here is to avoid going beyond the end of the fixed size buffer.

Right, surely though the kcontrol names are always null terminated? In any case, looks more safe to strncmp().

They probably should be but it's easy to get it wrong and hit exactly the array size.