Commit 36ce6dad authored by Cornelia Huck's avatar Cornelia Huck Committed by Greg Kroah-Hartman

driver core: Suppress sysfs warnings for device_rename().

driver core: Suppress sysfs warnings for device_rename().

Renaming network devices to an already existing name is not
something we want sysfs to print a scary warning for, since the
callers can deal with this correctly. So let's introduce
sysfs_create_link_nowarn() which gets rid of the common warning.
Signed-off-by: default avatarCornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 0ad1d6f3
...@@ -1345,8 +1345,9 @@ int device_rename(struct device *dev, char *new_name) ...@@ -1345,8 +1345,9 @@ int device_rename(struct device *dev, char *new_name)
if (old_class_name) { if (old_class_name) {
new_class_name = make_class_name(dev->class->name, &dev->kobj); new_class_name = make_class_name(dev->class->name, &dev->kobj);
if (new_class_name) { if (new_class_name) {
error = sysfs_create_link(&dev->parent->kobj, error = sysfs_create_link_nowarn(&dev->parent->kobj,
&dev->kobj, new_class_name); &dev->kobj,
new_class_name);
if (error) if (error)
goto out; goto out;
sysfs_remove_link(&dev->parent->kobj, old_class_name); sysfs_remove_link(&dev->parent->kobj, old_class_name);
...@@ -1354,8 +1355,8 @@ int device_rename(struct device *dev, char *new_name) ...@@ -1354,8 +1355,8 @@ int device_rename(struct device *dev, char *new_name)
} }
#else #else
if (dev->class) { if (dev->class) {
error = sysfs_create_link(&dev->class->p->class_subsys.kobj, error = sysfs_create_link_nowarn(&dev->class->p->class_subsys.kobj,
&dev->kobj, dev->bus_id); &dev->kobj, dev->bus_id);
if (error) if (error)
goto out; goto out;
sysfs_remove_link(&dev->class->p->class_subsys.kobj, sysfs_remove_link(&dev->class->p->class_subsys.kobj,
......
...@@ -398,7 +398,7 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, ...@@ -398,7 +398,7 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
} }
/** /**
* sysfs_add_one - add sysfs_dirent to parent * __sysfs_add_one - add sysfs_dirent to parent without warning
* @acxt: addrm context to use * @acxt: addrm context to use
* @sd: sysfs_dirent to be added * @sd: sysfs_dirent to be added
* *
...@@ -417,7 +417,7 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, ...@@ -417,7 +417,7 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
* 0 on success, -EEXIST if entry with the given name already * 0 on success, -EEXIST if entry with the given name already
* exists. * exists.
*/ */
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
{ {
if (sysfs_find_dirent(acxt->parent_sd, sd->s_name)) if (sysfs_find_dirent(acxt->parent_sd, sd->s_name))
return -EEXIST; return -EEXIST;
...@@ -434,6 +434,39 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) ...@@ -434,6 +434,39 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
return 0; return 0;
} }
/**
* sysfs_add_one - add sysfs_dirent to parent
* @acxt: addrm context to use
* @sd: sysfs_dirent to be added
*
* Get @acxt->parent_sd and set sd->s_parent to it and increment
* nlink of parent inode if @sd is a directory and link into the
* children list of the parent.
*
* This function should be called between calls to
* sysfs_addrm_start() and sysfs_addrm_finish() and should be
* passed the same @acxt as passed to sysfs_addrm_start().
*
* LOCKING:
* Determined by sysfs_addrm_start().
*
* RETURNS:
* 0 on success, -EEXIST if entry with the given name already
* exists.
*/
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
{
int ret;
ret = __sysfs_add_one(acxt, sd);
if (ret == -EEXIST) {
printk(KERN_WARNING "sysfs: duplicate filename '%s' "
"can not be created\n", sd->s_name);
WARN_ON(1);
}
return ret;
}
/** /**
* sysfs_remove_one - remove sysfs_dirent from parent * sysfs_remove_one - remove sysfs_dirent from parent
* @acxt: addrm context to use * @acxt: addrm context to use
......
...@@ -19,13 +19,8 @@ ...@@ -19,13 +19,8 @@
#include "sysfs.h" #include "sysfs.h"
/** static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
* sysfs_create_link - create symlink between two objects. const char *name, int warn)
* @kobj: object whose directory we're creating the link in.
* @target: object we're pointing to.
* @name: name of the symlink.
*/
int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name)
{ {
struct sysfs_dirent *parent_sd = NULL; struct sysfs_dirent *parent_sd = NULL;
struct sysfs_dirent *target_sd = NULL; struct sysfs_dirent *target_sd = NULL;
...@@ -65,7 +60,10 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char ...@@ -65,7 +60,10 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
target_sd = NULL; /* reference is now owned by the symlink */ target_sd = NULL; /* reference is now owned by the symlink */
sysfs_addrm_start(&acxt, parent_sd); sysfs_addrm_start(&acxt, parent_sd);
error = sysfs_add_one(&acxt, sd); if (warn)
error = sysfs_add_one(&acxt, sd);
else
error = __sysfs_add_one(&acxt, sd);
sysfs_addrm_finish(&acxt); sysfs_addrm_finish(&acxt);
if (error) if (error)
...@@ -79,6 +77,33 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char ...@@ -79,6 +77,33 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
return error; return error;
} }
/**
* sysfs_create_link - create symlink between two objects.
* @kobj: object whose directory we're creating the link in.
* @target: object we're pointing to.
* @name: name of the symlink.
*/
int sysfs_create_link(struct kobject *kobj, struct kobject *target,
const char *name)
{
return sysfs_do_create_link(kobj, target, name, 1);
}
/**
* sysfs_create_link_nowarn - create symlink between two objects.
* @kobj: object whose directory we're creating the link in.
* @target: object we're pointing to.
* @name: name of the symlink.
*
* This function does the same as sysf_create_link(), but it
* doesn't warn if the link already exists.
*/
int sysfs_create_link_nowarn(struct kobject *kobj, struct kobject *target,
const char *name)
{
return sysfs_do_create_link(kobj, target, name, 0);
}
/** /**
* sysfs_remove_link - remove symlink in object's directory. * sysfs_remove_link - remove symlink in object's directory.
* @kobj: object we're acting for. * @kobj: object we're acting for.
......
...@@ -107,6 +107,7 @@ struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd); ...@@ -107,6 +107,7 @@ struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
void sysfs_put_active_two(struct sysfs_dirent *sd); void sysfs_put_active_two(struct sysfs_dirent *sd);
void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
struct sysfs_dirent *parent_sd); struct sysfs_dirent *parent_sd);
int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
......
...@@ -101,6 +101,9 @@ void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr); ...@@ -101,6 +101,9 @@ void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
const char *name); const char *name);
int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
struct kobject *target,
const char *name);
void sysfs_remove_link(struct kobject *kobj, const char *name); void sysfs_remove_link(struct kobject *kobj, const char *name);
int __must_check sysfs_create_group(struct kobject *kobj, int __must_check sysfs_create_group(struct kobject *kobj,
...@@ -180,6 +183,13 @@ static inline int sysfs_create_link(struct kobject *kobj, ...@@ -180,6 +183,13 @@ static inline int sysfs_create_link(struct kobject *kobj,
return 0; return 0;
} }
static inline int sysfs_create_link_nowarn(struct kobject *kobj,
struct kobject *target,
const char *name)
{
return 0;
}
static inline void sysfs_remove_link(struct kobject *kobj, const char *name) static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
{ {
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment