[Cbe-oss-dev] [PATCH] spufs: use simple_attr again

Christoph Hellwig hch at lst.de
Sat Feb 9 18:50:18 EST 2008


Now that the libfs.c simple attrs have been update to allow for error
returns we can switch spufs to use them again instead of our local copy.


Signed-off-by: Christoph Hellwig <hch at lst.de>

Index: linux-2.6/arch/powerpc/platforms/cell/spufs/file.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/file.c	2008-02-09 08:41:49.000000000 +0100
+++ linux-2.6/arch/powerpc/platforms/cell/spufs/file.c	2008-02-09 08:42:32.000000000 +0100
@@ -41,121 +41,6 @@
 
 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
 
-/* Simple attribute files */
-struct spufs_attr {
-	int (*get)(void *, u64 *);
-	int (*set)(void *, u64);
-	char get_buf[24];       /* enough to store a u64 and "\n\0" */
-	char set_buf[24];
-	void *data;
-	const char *fmt;        /* format for read operation */
-	struct mutex mutex;     /* protects access to these buffers */
-};
-
-static int spufs_attr_open(struct inode *inode, struct file *file,
-		int (*get)(void *, u64 *), int (*set)(void *, u64),
-		const char *fmt)
-{
-	struct spufs_attr *attr;
-
-	attr = kmalloc(sizeof(*attr), GFP_KERNEL);
-	if (!attr)
-		return -ENOMEM;
-
-	attr->get = get;
-	attr->set = set;
-	attr->data = inode->i_private;
-	attr->fmt = fmt;
-	mutex_init(&attr->mutex);
-	file->private_data = attr;
-
-	return nonseekable_open(inode, file);
-}
-
-static int spufs_attr_release(struct inode *inode, struct file *file)
-{
-       kfree(file->private_data);
-	return 0;
-}
-
-static ssize_t spufs_attr_read(struct file *file, char __user *buf,
-		size_t len, loff_t *ppos)
-{
-	struct spufs_attr *attr;
-	size_t size;
-	ssize_t ret;
-
-	attr = file->private_data;
-	if (!attr->get)
-		return -EACCES;
-
-	ret = mutex_lock_interruptible(&attr->mutex);
-	if (ret)
-		return ret;
-
-	if (*ppos) {		/* continued read */
-		size = strlen(attr->get_buf);
-	} else {		/* first read */
-		u64 val;
-		ret = attr->get(attr->data, &val);
-		if (ret)
-			goto out;
-
-		size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
-				 attr->fmt, (unsigned long long)val);
-	}
-
-	ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
-out:
-	mutex_unlock(&attr->mutex);
-	return ret;
-}
-
-static ssize_t spufs_attr_write(struct file *file, const char __user *buf,
-		size_t len, loff_t *ppos)
-{
-	struct spufs_attr *attr;
-	u64 val;
-	size_t size;
-	ssize_t ret;
-
-	attr = file->private_data;
-	if (!attr->set)
-		return -EACCES;
-
-	ret = mutex_lock_interruptible(&attr->mutex);
-	if (ret)
-		return ret;
-
-	ret = -EFAULT;
-	size = min(sizeof(attr->set_buf) - 1, len);
-	if (copy_from_user(attr->set_buf, buf, size))
-		goto out;
-
-	ret = len; /* claim we got the whole input */
-	attr->set_buf[size] = '\0';
-	val = simple_strtol(attr->set_buf, NULL, 0);
-	attr->set(attr->data, val);
-out:
-	mutex_unlock(&attr->mutex);
-	return ret;
-}
-
-#define DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt)	\
-static int __fops ## _open(struct inode *inode, struct file *file)	\
-{									\
-	__simple_attr_check_format(__fmt, 0ull);			\
-	return spufs_attr_open(inode, file, __get, __set, __fmt);	\
-}									\
-static struct file_operations __fops = {				\
-	.owner	 = THIS_MODULE,						\
-	.open	 = __fops ## _open,					\
-	.release = spufs_attr_release,					\
-	.read	 = spufs_attr_read,					\
-	.write	 = spufs_attr_write,					\
-};
-
-
 static int
 spufs_mem_open(struct inode *inode, struct file *file)
 {
@@ -1306,7 +1191,7 @@ static int __##__get(void *data, u64 *va
 									\
 	return 0;							\
 }									\
-DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
+DEFINE_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
 
 static int spufs_signal1_type_set(void *data, u64 val)
 {



More information about the cbe-oss-dev mailing list