Skip to contentSkip to conversation

serial: core: Replace strncmp()+strlen() with plain strcmp()

PATCH In review Andy Shevchenko 1 participant 3 messages Jul 27, 2023 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: core: Replace strncmp()+strlen() with plain strcmp()

There is no sense to call strlen() ahead of strncmp(). The same effect can be achieved by calling strcmp() directly. Replace strncmp()+strlen() with plain strcmp().

---
 drivers/tty/serial/serial_base_bus.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/tty/serial/serial_base_bus.c +1 -3
index 6ff59c89d867..bd056e6dca2f 100644
@@ -21,9 +21,7 @@ static bool serial_base_initialized;
 
 static int serial_base_match(struct device *dev, struct device_driver *drv)
 {
-	int len = strlen(drv->name);
-
-	return !strncmp(dev_name(dev), drv->name, len);
+	return !strcmp(dev_name(dev), drv->name);
 }
 
 static struct bus_type serial_base_bus_type = {
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw
Quoted 3 lines · Andy Shevchenko

There is no sense to call strlen() ahead of strncmp(). The same effect can be achieved by calling strcmp() directly. Replace strncmp()+strlen() with plain strcmp().

It seems I will have more against serial core, perhaps it makes sense to unite them in a single series.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

There is no sense to call strlen() ahead of strncmp(). The same effect can be achieved by calling strcmp() directly. Replace strncmp()+strlen() with plain strcmp().

It seems I will have more against serial core, perhaps it makes sense to unite them in a single series.

Actually this change is simply wrong. Sorry for the noise.

Signature · 2 lines
With Best Regards,
Andy Shevchenko