Make KOBJ_NAME_LEN match BUS_ID_SIZE
PATCH 1/1 Make KOBJ_NAME_LEN match BUS_ID_SIZE
This was causing me all sorts of problems with linux1394's 16-18 byte long bus_id lengths. The sysfs names were all broken.
This not only makes KOBJ_NAME_LEN match BUS_ID_SIZE, but fixes the strncpy's in drivers/base/ so that it can't happen again (atleast the strings will be null terminated).
Index: include/linux/kobject.h
===================================================================
RCS file: /home/scm/linux-2.5/include/linux/kobject.h,v retrieving revision 1.11
linux/kobject.h +1 -1
@@ -12,7 +12,7 @@#include <linux/rwsem.h> #include <asm/atomic.h> -#define KOBJ_NAME_LEN 16 +#define KOBJ_NAME_LEN 20struct kobject {char name[KOBJ_NAME_LEN ];
Index: drivers/base/bus.c
===================================================================
RCS file: /home/scm/linux-2.5/drivers/base/bus.c,v retrieving revision 1.24
base/bus.c +2 -0
@@ -432,6 +432,7 @@pr_debug ("bus %s: add driver %s\n" ,bus->name,drv->name);strncpy (drv->kobj.name,drv->name,KOBJ_NAME_LEN ); + drv->kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ; drv->kobj.kset = &bus->drivers;if ((error =kobject_register (&drv->kobj))) {
@@ -541,6 +542,7 @@int bus_register (struct bus_type * bus) {strncpy (bus->subsys.kset.kobj.name,bus->name,KOBJ_NAME_LEN ); + bus->subsys.kset.kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ;subsys_set_kset (bus,bus_subsys);subsystem_register (&bus->subsys);
Index: drivers/base/class.c
===================================================================
RCS file: /home/scm/linux-2.5/drivers/base/class.c,v retrieving revision 1.18
base/class.c +2 -0
@@ -89,6 +89,7 @@INIT_LIST_HEAD (&cls->interfaces);strncpy (cls->subsys.kset.kobj.name,cls->name,KOBJ_NAME_LEN ); + cls->subsys.kset.kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ;subsys_set_kset (cls,class_subsys);subsystem_register (&cls->subsys);
@@ -259,6 +260,7 @@/* first, register with generic layer. */ strncpy (class_dev->kobj.name, class_dev->class_id,KOBJ_NAME_LEN ); + class_dev->kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ;kobj_set_kset_s (class_dev, class_obj_subsys);if (parent) class_dev->kobj.parent = &parent->subsys.kset.kobj;
Index: drivers/base/core.c
===================================================================
RCS file: /home/scm/linux-2.5/drivers/base/core.c,v retrieving revision 1.43
base/core.c +1 -0
@@ -214,6 +214,7 @@/* first, register with generic layer. */ strncpy (dev->kobj.name,dev->bus_id,KOBJ_NAME_LEN ); + dev->kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ;kobj_set_kset_s (dev,devices_subsys);if (parent) dev->kobj.parent = &parent->kobj;
Quoted 6 lines · Ben Collins
This was causing me all sorts of problems with linux1394's 16-18 byte long
bus_idlengths. The sysfs names were all broken.This not only makes
KOBJ_NAME_LENmatchBUS_ID_SIZE, but fixes the strncpy's indrivers/base/so that it can't happen again (atleast the strings will be null terminated).
What about defining BUS_ID_SIZE in terms of KOBJ_NAME_LEN?
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Ben Collins
This was causing me all sorts of problems with linux1394's 16-18 byte long
bus_idlengths. The sysfs names were all broken.This not only makes
KOBJ_NAME_LENmatchBUS_ID_SIZE, but fixes the strncpy's indrivers/base/so that it can't happen again (atleast the strings will be null terminated).What about defining
BUS_ID_SIZEin terms ofKOBJ_NAME_LEN?
Ok, then add this in addition to the previous patch.
Index: include/linux/device.h
===================================================================
RCS file: /home/scm/linux-2.5/include/linux/device.h,v retrieving revision 1.48
linux/device.h +1 -1
@@ -35,7 +35,7 @@#define DEVICE_NAME_SIZE 50#define DEVICE_NAME_HALF __stringify(20)/* Less than half to accommodate slop */ #define DEVICE_ID_SIZE 32 -#define BUS_ID_SIZE 20 +#define BUS_ID_SIZE KOBJ_NAME_LENenum {
Quoted 5 lines · Ben Collins
Quoted 4 lines · Christoph Hellwig
Quoted 3 lines · Ben Collins
This was causing me all sorts of problems with linux1394's 16-18 byte long
bus_idlengths. The sysfs names were all broken.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
This not only makes
KOBJ_NAME_LENmatchBUS_ID_SIZE, but fixes the strncpy's indrivers/base/so that it can't happen again (atleast the strings will be null terminated).What about defining
BUS_ID_SIZEin terms ofKOBJ_NAME_LEN?Ok, then add this in addition to the previous patch.
I'll add this, and sync with Linus this week, if he doesn't pick it up.
Thanks,
-pat
Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Quoted 12 lines · Patrick Mochel
Quoted 9 lines · Ben Collins
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Ben Collins
This was causing me all sorts of problems with linux1394's 16-18 byte long
bus_idlengths. The sysfs names were all broken.This not only makes
KOBJ_NAME_LENmatchBUS_ID_SIZE, but fixes the strncpy's indrivers/base/so that it can't happen again (atleast the strings will be null terminated).
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
What about defining
BUS_ID_SIZEin terms ofKOBJ_NAME_LEN?Ok, then add this in addition to the previous patch.
I'll add this, and sync with Linus this week, if he doesn't pick it up.
*sigh* Patrick, you accepted the BUS_ID_SIZE change without the original patch, so now BUS_ID_SIZE is back to 16 bytes.
Linus, please apply this patch to get things right again.
-------
This was causing me all sorts of problems with linux1394's 16-18 byte long bus_id lengths. The sysfs names were all broken.
This not only makes KOBJ_NAME_LEN match BUS_ID_SIZE, but fixes the strncpy's in drivers/base/ so that it can't happen again (atleast the strings will be null terminated).
Index: include/linux/kobject.h
===================================================================
RCS file: /home/scm/linux-2.5/include/linux/kobject.h,v retrieving revision 1.11
linux/kobject.h +1 -1
@@ -12,7 +12,7 @@#include <linux/rwsem.h> #include <asm/atomic.h> -#define KOBJ_NAME_LEN 16 +#define KOBJ_NAME_LEN 20struct kobject {char name[KOBJ_NAME_LEN ];
Index: drivers/base/bus.c
===================================================================
RCS file: /home/scm/linux-2.5/drivers/base/bus.c,v retrieving revision 1.24
base/bus.c +2 -0
@@ -432,6 +432,7 @@pr_debug ("bus %s: add driver %s\n" ,bus->name,drv->name);strncpy (drv->kobj.name,drv->name,KOBJ_NAME_LEN ); + drv->kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ; drv->kobj.kset = &bus->drivers;if ((error =kobject_register (&drv->kobj))) {
@@ -541,6 +542,7 @@int bus_register (struct bus_type * bus) {strncpy (bus->subsys.kset.kobj.name,bus->name,KOBJ_NAME_LEN ); + bus->subsys.kset.kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ;subsys_set_kset (bus,bus_subsys);subsystem_register (&bus->subsys);
Index: drivers/base/class.c
===================================================================
RCS file: /home/scm/linux-2.5/drivers/base/class.c,v retrieving revision 1.18
base/class.c +2 -0
@@ -89,6 +89,7 @@INIT_LIST_HEAD (&cls->interfaces);strncpy (cls->subsys.kset.kobj.name,cls->name,KOBJ_NAME_LEN ); + cls->subsys.kset.kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ;subsys_set_kset (cls,class_subsys);subsystem_register (&cls->subsys);
@@ -259,6 +260,7 @@/* first, register with generic layer. */ strncpy (class_dev->kobj.name, class_dev->class_id,KOBJ_NAME_LEN ); + class_dev->kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ;kobj_set_kset_s (class_dev, class_obj_subsys);if (parent) class_dev->kobj.parent = &parent->subsys.kset.kobj;
Index: drivers/base/core.c
===================================================================
RCS file: /home/scm/linux-2.5/drivers/base/core.c,v retrieving revision 1.43
base/core.c +1 -0
@@ -214,6 +214,7 @@/* first, register with generic layer. */ strncpy (dev->kobj.name,dev->bus_id,KOBJ_NAME_LEN ); + dev->kobj.name[KOBJ_NAME_LEN -1 ] ='\0' ;kobj_set_kset_s (dev,devices_subsys);if (parent) dev->kobj.parent = &parent->kobj;
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Quoted 15 lines · Ben Collins
Quoted 14 lines · Patrick Mochel
Quoted 11 lines · Ben Collins
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Ben Collins
This was causing me all sorts of problems with linux1394's 16-18 byte long
bus_idlengths. The sysfs names were all broken.This not only makes
KOBJ_NAME_LENmatchBUS_ID_SIZE, but fixes the strncpy's indrivers/base/so that it can't happen again (atleast the strings will be null terminated).What about defining
BUS_ID_SIZEin terms ofKOBJ_NAME_LEN?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Ok, then add this in addition to the previous patch.
I'll add this, and sync with Linus this week, if he doesn't pick it up.
*sigh* Patrick, you accepted the
BUS_ID_SIZEchange without the original patch, so nowBUS_ID_SIZEis back to 16 bytes.Linus, please apply this patch to get things right again.
Well, it seems this patch has bad interaction with the Yamaha ALSA sound driver (aka snd-ymfpci). Don't know why, but changing KOBJ_NAME_LEN from 16 to 20, causes snd-ymfpci.ko to oops.
If you have the time, please take a look at another thread in the LKML called "pccard oops while booting".
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
In reply to Ben CollinsGiven that the problem with KOBJ_NAME_LEN == 20 affecting one snd driver has so far only been explained as a compiler bug, can I suggest this patch be applied? Even aside from the KOBJ_NAME_LEN == 20, the snprintf changes will keep things from breaking in other ways that are current now.
linux/kobject.h +1 -1
@@ -12,7 +12,7 @@#include <linux/rwsem.h> #include <asm/atomic.h> -#define KOBJ_NAME_LEN 16 +#define KOBJ_NAME_LEN 20struct kobject {char name[KOBJ_NAME_LEN ];
base/class.c +4 -3
@@ -87,8 +87,9 @@INIT_LIST_HEAD (&cls->children);INIT_LIST_HEAD (&cls->interfaces); - -strncpy (cls->subsys.kset.kobj.name,cls->name,KOBJ_NAME_LEN ); + +snprintf (cls->subsys.kset.kobj.name,KOBJ_NAME_LEN ,"%s" , + cls->name);subsys_set_kset (cls,class_subsys);subsystem_register (&cls->subsys);
@@ -258,7 +259,7 @@ class_dev->class_id);/* first, register with generic layer. */ -strncpy (class_dev->kobj.name, class_dev->class_id,KOBJ_NAME_LEN ); +snprintf (class_dev->kobj.name,KOBJ_NAME_LEN ,"%s" , class_dev->class_id);kobj_set_kset_s (class_dev, class_obj_subsys);if (parent) class_dev->kobj.parent = &parent->subsys.kset.kobj;
base/core.c +1 -1
@@ -211,7 +211,7 @@ dev->bus_id, dev->name);/* first, register with generic layer. */ -strncpy (dev->kobj.name,dev->bus_id,KOBJ_NAME_LEN ); +snprintf (dev->kobj.name,KOBJ_NAME_LEN ,"%s" , dev->bus_id);if (parent) dev->kobj.parent = &parent->kobj;
base/bus.c +3 -2
@@ -431,7 +431,7 @@if (bus) {pr_debug ("bus %s: add driver %s\n" ,bus->name,drv->name); -strncpy (drv->kobj.name,drv->name,KOBJ_NAME_LEN ); +snprintf (drv->kobj.name,KOBJ_NAME_LEN ,"%s" , drv->name); drv->kobj.kset = &bus->drivers;if ((error =kobject_register (&drv->kobj))) {
@@ -540,7 +540,8 @@*/ int bus_register (struct bus_type * bus) { -strncpy (bus->subsys.kset.kobj.name,bus->name,KOBJ_NAME_LEN ); +snprintf (bus->subsys.kset.kobj.name,KOBJ_NAME_LEN ,"%s" , + bus->name);subsys_set_kset (bus,bus_subsys);subsystem_register (&bus->subsys);
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Quoted 6 lines · Ben Collins
Given that the problem with
KOBJ_NAME_LEN== 20 affecting one snd driver has so far only been explained as a compiler bug, can I suggest this patch be applied? Even aside from theKOBJ_NAME_LEN== 20, the snprintf changes will keep things from breaking in other ways that are current now.
I hate using snprintf() for this kind of mindless string copy opertation.
Yeah, "strncpy()" is a frigging disaster when it comes to '\0', in many ways. We should probably disallow using strncpy(), and aim for a _sane_ implementation that does what we actually want (none of that zero-padding crap, and _always_ put a NUL at the end). I bet that is what most current strncpy() users actually would want.
But switching it over to "snprintf()" is overkill.
How about just adding a sane
int copy_string(char *dest, const char *src, int len)
{
int size;
if (!len)
return 0;
size = strlen(src);
if (size >= len)
size = len-1;
memcpy(dest, src, size);
dest[size] = '\0';
return size;
}which is what pretty much everybody really _wants_ to have anyway? We should deprecate "strncpy()" within the kernel entirely.
Linus
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Quoted 2 lines
which is what pretty much everybody really _wants_ to have anyway? We should deprecate "
strncpy()" within the kernel entirely.
Amen.
If you could atleast apply the KOBJ_NAME_LEN part of the patch, I'll start doing a much wider scope patch of replacing strncpy in the whole kernel.
Signature · 4 lines
Debian - http://www.debian.org/ Linux 1394 - http://www.linux1394.org/ Subversion - http://subversion.tigris.org/ Deqo - http://www.deqo.com/
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
In reply to Linus TorvaldsQuoted 2 lines · Linus Torvalds
How about just adding a sane
intcopy_string(char *dest, const char *src, int len)
[...]
If you're going to do this, it might make sense to call it "strlcpy" for consistency with the OpenBSD-introduced function of the same name that's getting included in a lot of userspace these days...
<http://www.courtesan.com/todd/papers/strlcpy.html>
Signature · 1 line
Adam Sampson <[email protected]> <http://azz.us-lot.org/>
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Quoted 4 lines · Adam Sampson
If you're going to do this, it might make sense to call it "strlcpy" for consistency with the OpenBSD-introduced function of the same name that's getting included in a lot of userspace these days...
Sure, done. I'll check it in asap (and I'll make the devfs parts that Ben was unhappy about use it too).
Somebody (else ;) should probably go through our current uses of strncpy() and see if they make sense. Some of them probably do, but I suspect anything name/path related does not.
Linus
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Adam Sampson
If you're going to do this, it might make sense to call it "strlcpy" for consistency with the OpenBSD-introduced function of the same name that's getting included in a lot of userspace these days...
Quoted 6 lines
Sure, done. I'll check it in asap (and I'll make the devfs parts that Ben was unhappy about use it too).
Somebody (else ;) should probably go through our current uses of
strncpy()and see if they make sense. Some of them probably do, but I suspect anything name/path related does not.
Please hold off. I have a better patch that includes strlcat. Actually tested.
Signature · 4 lines
Debian - http://www.debian.org/ Linux 1394 - http://www.linux1394.org/ Subversion - http://subversion.tigris.org/ Deqo - http://www.deqo.com/
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
In reply to Linus TorvaldsQuoted 16 lines · Linus Torvalds
How about just adding a sane
int copy_string(char *dest, const char *src, int len) { int size; if (!len) return 0; size = strlen(src); if (size >= len) size = len-1; memcpy(dest, src, size); dest[size] = '\0'; return size; }
The return value here isn't particularly useful. The OpenBSD strlcpy/strlcat variant tell you how big the result should have been so that you can realloc if need be.
Signature · 1 line
Matt Mackall : http://www.selenic.com : of or relating to the moon
RE: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Hi Matt.
Quoted 16 lines
Quoted 15 lines
How about just adding a sane
int copy_string(char *dest, const char *src, int len) { int size; if (!len) return 0; size = strlen(src); if (size >= len) size = len-1; memcpy(dest, src, size); dest[size] = '\0'; return size; }
Quoted 3 lines
The return value here isn't particularly useful. The OpenBSD strlcpy/strlcat variant tell you how big the result should have been so that you can realloc if need be.
Something along the lines of...
int strlcpy(char *tgt, char *src, int len)
{
int size = strlen(src);
if (size < len)
strcpy(tgt, src);
else {
memcpy(tgt, src, len-1);
tgt[len] = '\0';
}
return size;
}...reindented according to standards (which I don't have to hand).
Best wishes from Riley.
---
* Nothing as pretty as a smile, nothing as ugly as a frown.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.483 / Virus Database: 279 - Release Date: 19-May-2003
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
In reply to Matt MackallQuoted 3 lines · Matt Mackall
The return value here isn't particularly useful. The OpenBSD strlcpy/strlcat variant tell you how big the result should have been so that you can realloc if need be.
A quick grep of the current source tree seems to indicate that there aren't any uses of 'strncpy' that actually save or check the return value.
As such, actually *using* the return value would make for a job for the kernel janitors, to actually do something useful at all 650 or so uses.
Given that the kernel probably *shouldn't* be trying to strlcpy() into a destination that it won't fit, it may be more useful to do a BUG_ON() or similar (feel free to use a 'goto too_long;' if you prefer ;)
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Quoted 11 lines · On Sun, May 25, 2003 at 02:13:02PM -0400, [email protected] wrote:
Quoted 3 lines · Matt Mackall
The return value here isn't particularly useful. The OpenBSD strlcpy/strlcat variant tell you how big the result should have been so that you can realloc if need be.
A quick grep of the current source tree seems to indicate that there aren't any uses of 'strncpy' that actually save or check the return value.
As such, actually *using* the return value would make for a job for the kernel janitors, to actually do something useful at all 650 or so uses.
The kernel, fortunately, isn't Perl or the like and really isn't interested in strings outside the context of things like pathnames, which realistically have to have finite limits. So while there probably aren't a lot of uses for a return val, for the places where there are, min(bufsize, optimalsize) is going to be less useful than just optimalsize as you already know bufsize.
Quoted 3 lines
Given that the kernel probably *shouldn't* be trying to
strlcpy()into a destination that it won't fit, it may be more useful to do aBUG_ON()or similar (feel free to use a 'gototoo_long;' if you prefer ;)
Outside of pathnames type things, where there's a well-defined return code (ENAMETOOLONG), we probably end up not caring overmuch about truncation..
Signature · 1 line
Matt Mackall : http://www.selenic.com : of or relating to the moon
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
In reply to Linus TorvaldsQuoted 3 lines
which is what pretty much everybody really _wants_ to have anyway? We should deprecate "
strncpy()" within the kernel entirely.
Let's try this one for size. First patch adds strlcpy and strlcat. The second patch applies to my initial offender, drivers/base.
I'll do obvious conversions of the rest of tree over the next week and hope that the architectures will be able to do optimized versions in the same time frame. If everything works out ok, strncpy (and maybe strncat) can be either marked deprecated or just removed altogether.
Signature · 4 lines
Debian - http://www.debian.org/ Linux 1394 - http://www.linux1394.org/ Subversion - http://subversion.tigris.org/ Deqo - http://www.deqo.com/
ksyms.c +2 -0
@@ -578,6 +578,8 @@EXPORT_SYMBOL (strnicmp);EXPORT_SYMBOL (strspn);EXPORT_SYMBOL (strsep); +EXPORT_SYMBOL (strlcat); +EXPORT_SYMBOL (strlcpy);/* software interrupts */ EXPORT_SYMBOL (tasklet_init);
linux/string.h +6 -0
@@ -25,12 +25,18 @@#ifndef __HAVE_ARCH_STRCPYextern char *strcpy (char *,const char *);#endif +#ifndef __HAVE_ARCH_STRLCPY +extern size_t strlcpy (char *dest,const char *src,size_t size); +#endif #ifndef __HAVE_ARCH_STRNCPYextern char *strncpy (char *,const char *,__kernel_size_t );#endif #ifndef __HAVE_ARCH_STRCATextern char *strcat (char *,const char *);#endif +#ifndef __HAVE_ARCH_STRLCAT +extern size_t strlcat (char *dest,const char *src,size_t size); +#endif #ifndef __HAVE_ARCH_STRNCATextern char *strncat (char *,const char *,__kernel_size_t );#endif
string.c +109 -1
129 lines not on this page · raw message
base/class.c +3 -3
@@ -87,8 +87,8 @@INIT_LIST_HEAD (&cls->children);INIT_LIST_HEAD (&cls->interfaces); - -strncpy (cls->subsys.kset.kobj.name,cls->name,KOBJ_NAME_LEN ); + +strlcpy (cls->subsys.kset.kobj.name, cls->name,KOBJ_NAME_LEN );subsys_set_kset (cls,class_subsys);subsystem_register (&cls->subsys);
@@ -258,7 +258,7 @@ class_dev->class_id);/* first, register with generic layer. */ -strncpy (class_dev->kobj.name, class_dev->class_id,KOBJ_NAME_LEN ); +strlcpy (class_dev->kobj.name, class_dev->class_id,KOBJ_NAME_LEN );kobj_set_kset_s (class_dev, class_obj_subsys);if (parent) class_dev->kobj.parent = &parent->subsys.kset.kobj;
base/sys.c +2 -2
@@ -63,8 +63,8 @@ error =device_register (&root->dev);if (!error) { -strncpy (root->sysdev.bus_id,"sys" ,BUS_ID_SIZE ); -strncpy (root->sysdev.name,"System Bus" ,DEVICE_NAME_SIZE ); +strlcpy (root->sysdev.bus_id,"sys" ,BUS_ID_SIZE ); +strlcpy (root->sysdev.name,"System Bus" ,DEVICE_NAME_SIZE ); root->sysdev.parent = &root->dev; error =device_register (&root->sysdev); };
base/core.c +1 -1
@@ -211,7 +211,7 @@ dev->bus_id, dev->name);/* first, register with generic layer. */ -strncpy (dev->kobj.name,dev->bus_id,KOBJ_NAME_LEN ); +strlcpy (dev->kobj.name, dev->bus_id,KOBJ_NAME_LEN );if (parent) dev->kobj.parent = &parent->kobj;
base/bus.c +4 -4
@@ -431,7 +431,7 @@if (bus) {pr_debug ("bus %s: add driver %s\n" ,bus->name,drv->name); -strncpy (drv->kobj.name,drv->name,KOBJ_NAME_LEN ); +strlcpy (drv->kobj.name, drv->name,KOBJ_NAME_LEN ); drv->kobj.kset = &bus->drivers;if ((error =kobject_register (&drv->kobj))) {
@@ -540,15 +540,15 @@*/ int bus_register (struct bus_type * bus) { -strncpy (bus->subsys.kset.kobj.name,bus->name,KOBJ_NAME_LEN ); +strlcpy (bus->subsys.kset.kobj.name, bus->name,KOBJ_NAME_LEN );subsys_set_kset (bus,bus_subsys);subsystem_register (&bus->subsys); -snprintf (bus->devices.kobj.name,KOBJ_NAME_LEN ,"devices" ); +strlcpy (bus->devices.kobj.name,"devices" ,KOBJ_NAME_LEN ); bus->devices.subsys = &bus->subsys;kset_register (&bus->devices); -snprintf (bus->drivers.kobj.name,KOBJ_NAME_LEN ,"drivers" ); +strlcpy (bus->drivers.kobj.name,"drivers" ,KOBJ_NAME_LEN ); bus->drivers.subsys = &bus->subsys; bus->drivers.ktype = &ktype_driver;kset_register (&bus->drivers);
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
In reply to Linus TorvaldsQuoted 15 lines · Linus Torvalds
How about just adding a sane
int copy_string(char *dest, const char *src, int len) { int size; if (!len) return 0; size = strlen(src); if (size >= len) size = len-1; memcpy(dest, src, size); dest[size] = '\0'; return size; }
Just catching up...
Most people will think: "But that's not efficient!" he first determines the size using strlen, and only then does he start a memcpy.
In fact most modern processors priming the cache and then doing the copy is noticably faster or just a teeny little bit slower.
Roger.
Signature · 3 lines
** [email protected] ** http://www.BitWizard.nl/ ** +31-15-2600998 ** *-- BitWizard writes Linux device drivers for any device you may have! --* * I didn't say it was your fault. I said I was going to blame it on you. *
Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
In reply to Ben CollinsQuoted 3 lines · Ben Collins
Given that the problem with
KOBJ_NAME_LEN== 20 affecting one snd driver has so far only been explained as a compiler bug, can I suggest this patch be applied?
No one has confirmed that it is a compiler bug yet. We only suspect that something in the yamaha driver is getting miscompiled. We don't know what, we don't know how, we don't know why.
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html