Commit a9ae3e34 authored by Patrick Mochel's avatar Patrick Mochel

device symlinks: just pass name, not struct driver_file_entry to driverfs_create_symlink

symlinks now only use the name field of the struct driver_file_entry, so instead of allocating
a new one each time we want to create one, this changes the API to only accept the name (since
the driverfs core will never use the other fields either)

This also guarantees that we won't leak the memory for the entry when the device goes away:
Since the other entries aren't dynamically allocated, and driverfs doesn't free them, we would
have to free them ourselves. It's not really necessary, so this is another win for us.
parent 6e0b96ce
......@@ -93,22 +93,6 @@ static void fill_devpath(struct device * dev, char * path, int length)
pr_debug("%s: path = '%s'\n",__FUNCTION__,path);
}
static int create_symlink(struct driver_dir_entry * parent, char * name, char * path)
{
struct driver_file_entry * entry;
int error;
entry = kmalloc(sizeof(struct driver_file_entry),GFP_KERNEL);
if (!entry)
return -ENOMEM;
entry->name = name;
entry->mode = S_IRUGO;
error = driverfs_create_symlink(parent,entry,path);
if (error)
kfree(entry);
return error;
}
int device_bus_link(struct device * dev)
{
char * path;
......@@ -138,8 +122,7 @@ int device_bus_link(struct device * dev)
strcpy(path,"../../..");
fill_devpath(dev,path,length);
error = create_symlink(&dev->bus->device_dir,dev->bus_id,path);
error = driverfs_create_symlink(&dev->bus->device_dir,dev->bus_id,path);
kfree(path);
return error;
}
......
......@@ -138,7 +138,7 @@ static int driverfs_mknod(struct inode *dir, struct dentry *dentry, int mode, in
/* only allow create if ->d_fsdata is not NULL (so we can assume it
* comes from the driverfs API below. */
if (dentry->d_fsdata && inode) {
if (inode) {
d_instantiate(dentry, inode);
dget(dentry);
error = 0;
......@@ -656,13 +656,12 @@ driverfs_create_file(struct driver_file_entry * entry,
*
*/
int driverfs_create_symlink(struct driver_dir_entry * parent,
struct driver_file_entry * entry,
char * target)
char * name, char * target)
{
struct dentry * dentry;
int error = 0;
if (!entry || !parent)
if (!parent)
return -EINVAL;
get_mount();
......@@ -672,11 +671,10 @@ int driverfs_create_symlink(struct driver_dir_entry * parent,
return -EINVAL;
}
down(&parent->dentry->d_inode->i_sem);
dentry = get_dentry(parent->dentry,entry->name);
if (!IS_ERR(dentry)) {
dentry->d_fsdata = (void *)entry;
dentry = get_dentry(parent->dentry,name);
if (!IS_ERR(dentry))
error = driverfs_symlink(parent->dentry->d_inode,dentry,target);
} else
else
error = PTR_ERR(dentry);
up(&parent->dentry->d_inode->i_sem);
if (error)
......
......@@ -54,8 +54,7 @@ driverfs_create_file(struct driver_file_entry * entry,
extern int
driverfs_create_symlink(struct driver_dir_entry * parent,
struct driver_file_entry * entry,
char * target);
char * name, char * target);
extern void
driverfs_remove_file(struct driver_dir_entry *, 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