diff mbox series

[v1,1/1] serial: core: Replace strncmp()+strlen() with plain strcmp()

Message ID 20230727090507.81962-1-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v1,1/1] serial: core: Replace strncmp()+strlen() with plain strcmp() | expand

Commit Message

Andy Shevchenko July 27, 2023, 9:05 a.m. UTC
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().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/serial_base_bus.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Andy Shevchenko July 27, 2023, 11:59 a.m. UTC | #1
On Thu, Jul 27, 2023 at 12:05:07PM +0300, Andy Shevchenko wrote:
> 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.
Andy Shevchenko July 27, 2023, 2:36 p.m. UTC | #2
On Thu, Jul 27, 2023 at 02:59:37PM +0300, Andy Shevchenko wrote:
> On Thu, Jul 27, 2023 at 12:05:07PM +0300, Andy Shevchenko wrote:
> > 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.
diff mbox series

Patch

diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/serial_base_bus.c
index 6ff59c89d867..bd056e6dca2f 100644
--- a/drivers/tty/serial/serial_base_bus.c
+++ b/drivers/tty/serial/serial_base_bus.c
@@ -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 = {