mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/6] fs: Drop needless OOM check
@ 2019-02-26 19:52 Andrey Smirnov
  2019-02-26 19:52 ` [PATCH 2/6] fs: ramfs: " Andrey Smirnov
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Andrey Smirnov @ 2019-02-26 19:52 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Drop needless OOM check since xzalloc() will never return NULL.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 fs/fs.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 1f6b3d346..65de82518 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -809,9 +809,6 @@ static int fillonedir(struct dir_context *ctx, const char *name, int namlen,
 	struct readdir_entry *entry;
 
 	entry = xzalloc(sizeof(*entry));
-	if (!entry)
-		return -ENOMEM;
-
 	memcpy(entry->d.d_name, name, namlen);
 	list_add_tail(&entry->list, &rd->dir->entries);
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/6] fs: ramfs: Drop needless OOM check
  2019-02-26 19:52 [PATCH 1/6] fs: Drop needless OOM check Andrey Smirnov
@ 2019-02-26 19:52 ` Andrey Smirnov
  2019-02-26 19:53 ` [PATCH 3/6] fs: Make use of cdev_erase() Andrey Smirnov
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2019-02-26 19:52 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Drop needless OOM check since xzalloc() will never return NULL.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 fs/ramfs.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/ramfs.c b/fs/ramfs.c
index 4fba40d31..3046afef3 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -403,8 +403,6 @@ static struct inode *ramfs_alloc_inode(struct super_block *sb)
 	struct ramfs_inode *node;
 
 	node = xzalloc(sizeof(*node));
-	if (!node)
-		return NULL;
 
 	return &node->inode;
 }
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/6] fs: Make use of cdev_erase()
  2019-02-26 19:52 [PATCH 1/6] fs: Drop needless OOM check Andrey Smirnov
  2019-02-26 19:52 ` [PATCH 2/6] fs: ramfs: " Andrey Smirnov
@ 2019-02-26 19:53 ` Andrey Smirnov
  2019-02-26 19:53 ` [PATCH 4/6] fs: Make use of cdev_flush() Andrey Smirnov
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2019-02-26 19:53 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Drop extra checks and explicit indirect call in devfs_erase() in
favour of using cdev_erase(), since it already does all of the above.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 fs/devfs.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/devfs.c b/fs/devfs.c
index a7400df1c..ce04d0243 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -78,13 +78,10 @@ static int devfs_erase(struct device_d *_dev, FILE *f, loff_t count, loff_t offs
 	if (cdev->flags & DEVFS_PARTITION_READONLY)
 		return -EPERM;
 
-	if (!cdev->ops->erase)
-		return -ENOSYS;
-
 	if (count + offset > cdev->size)
 		count = cdev->size - offset;
 
-	return cdev->ops->erase(cdev, count, offset + cdev->offset);
+	return cdev_erase(cdev, count, offset);
 }
 
 static int devfs_protect(struct device_d *_dev, FILE *f, size_t count, loff_t offset, int prot)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/6] fs: Make use of cdev_flush()
  2019-02-26 19:52 [PATCH 1/6] fs: Drop needless OOM check Andrey Smirnov
  2019-02-26 19:52 ` [PATCH 2/6] fs: ramfs: " Andrey Smirnov
  2019-02-26 19:53 ` [PATCH 3/6] fs: Make use of cdev_erase() Andrey Smirnov
@ 2019-02-26 19:53 ` Andrey Smirnov
  2019-02-26 19:53 ` [PATCH 5/6] fs: Drop unused code in fstat() Andrey Smirnov
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2019-02-26 19:53 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Drop extra checks and explicit indirect call in devfs_flush() in
favour of using cdev_flush(), since it already does all of the above.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 fs/devfs.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/devfs.c b/fs/devfs.c
index ce04d0243..d088c1a66 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -152,10 +152,7 @@ static int devfs_flush(struct device_d *_dev, FILE *f)
 {
 	struct cdev *cdev = f->priv;
 
-	if (cdev->ops->flush)
-		return cdev->ops->flush(cdev);
-
-	return 0;
+	return cdev_flush(cdev);
 }
 
 static int devfs_ioctl(struct device_d *_dev, FILE *f, int request, void *buf)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/6] fs: Drop unused code in fstat()
  2019-02-26 19:52 [PATCH 1/6] fs: Drop needless OOM check Andrey Smirnov
                   ` (2 preceding siblings ...)
  2019-02-26 19:53 ` [PATCH 4/6] fs: Make use of cdev_flush() Andrey Smirnov
@ 2019-02-26 19:53 ` Andrey Smirnov
  2019-02-26 19:53 ` [PATCH 6/6] fs: Simplify fd to FILE lookup code Andrey Smirnov
  2019-02-27  7:35 ` [PATCH 1/6] fs: Drop needless OOM check Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2019-02-26 19:53 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 fs/fs.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 65de82518..878a18e17 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -848,15 +848,12 @@ static void stat_inode(struct inode *inode, struct stat *s)
 int fstat(int fd, struct stat *s)
 {
 	FILE *f;
-	struct fs_device_d *fsdev;
 
 	if (check_fd(fd))
 		return -errno;
 
 	f = &files[fd];
 
-	fsdev = f->fsdev;
-
 	stat_inode(f->f_inode, s);
 
 	return 0;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 6/6] fs: Simplify fd to FILE lookup code
  2019-02-26 19:52 [PATCH 1/6] fs: Drop needless OOM check Andrey Smirnov
                   ` (3 preceding siblings ...)
  2019-02-26 19:53 ` [PATCH 5/6] fs: Drop unused code in fstat() Andrey Smirnov
@ 2019-02-26 19:53 ` Andrey Smirnov
  2019-02-27  7:35 ` [PATCH 1/6] fs: Drop needless OOM check Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Andrey Smirnov @ 2019-02-26 19:53 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Avoid a bit of repeating code by merging checking fd for correctness
and fd to FILE lookup into a single routine and converting the rest of
the code to use it.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 fs/fs.c | 83 +++++++++++++++++++++------------------------------------
 1 file changed, 30 insertions(+), 53 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 878a18e17..c6cb49996 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -171,14 +171,14 @@ static void put_file(FILE *f)
 	dput(f->dentry);
 }
 
-static int check_fd(int fd)
+static FILE *fd_to_file(int fd)
 {
 	if (fd < 0 || fd >= MAX_FILES || !files[fd].in_use) {
 		errno = EBADF;
-		return -errno;
+		return ERR_PTR(-errno);
 	}
 
-	return 0;
+	return &files[fd];
 }
 
 static int create(struct dentry *dir, struct dentry *dentry)
@@ -205,14 +205,12 @@ EXPORT_SYMBOL(creat);
 int ftruncate(int fd, loff_t length)
 {
 	struct fs_driver_d *fsdrv;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
 
-	f = &files[fd];
-
 	if (f->size == FILE_SIZE_STREAM)
 		return 0;
 
@@ -232,14 +230,12 @@ int ftruncate(int fd, loff_t length)
 int ioctl(int fd, int request, void *buf)
 {
 	struct fs_driver_d *fsdrv;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
 
-	f = &files[fd];
-
 	fsdrv = f->fsdev->driver;
 
 	if (fsdrv->ioctl)
@@ -279,14 +275,12 @@ out:
 ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
 {
 	loff_t pos;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
 
-	f = &files[fd];
-
 	pos = f->pos;
 	f->pos = offset;
 	ret = __read(f, buf, count);
@@ -298,14 +292,12 @@ EXPORT_SYMBOL(pread);
 
 ssize_t read(int fd, void *buf, size_t count)
 {
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
 
-	f = &files[fd];
-
 	ret = __read(f, buf, count);
 
 	if (ret > 0)
@@ -348,14 +340,12 @@ out:
 ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset)
 {
 	loff_t pos;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
 
-	f = &files[fd];
-
 	pos = f->pos;
 	f->pos = offset;
 	ret = __write(f, buf, count);
@@ -367,14 +357,12 @@ EXPORT_SYMBOL(pwrite);
 
 ssize_t write(int fd, const void *buf, size_t count)
 {
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
 
-	f = &files[fd];
-
 	ret = __write(f, buf, count);
 
 	if (ret > 0)
@@ -386,14 +374,12 @@ EXPORT_SYMBOL(write);
 int flush(int fd)
 {
 	struct fs_driver_d *fsdrv;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
 
-	f = &files[fd];
-
 	fsdrv = f->fsdev->driver;
 	if (fsdrv->flush)
 		ret = fsdrv->flush(&f->fsdev->dev, f);
@@ -406,17 +392,16 @@ int flush(int fd)
 	return ret;
 }
 
-loff_t lseek(int fildes, loff_t offset, int whence)
+loff_t lseek(int fd, loff_t offset, int whence)
 {
 	struct fs_driver_d *fsdrv;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	loff_t pos;
 	int ret;
 
-	if (check_fd(fildes))
+	if (IS_ERR(f))
 		return -1;
 
-	f = &files[fildes];
 	fsdrv = f->fsdev->driver;
 
 	ret = -EINVAL;
@@ -461,12 +446,11 @@ EXPORT_SYMBOL(lseek);
 int erase(int fd, loff_t count, loff_t offset)
 {
 	struct fs_driver_d *fsdrv;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
-	f = &files[fd];
 	if (offset >= f->size)
 		return 0;
 	if (count == ERASE_SIZE_ALL || count > f->size - offset)
@@ -490,12 +474,11 @@ EXPORT_SYMBOL(erase);
 int protect(int fd, size_t count, loff_t offset, int prot)
 {
 	struct fs_driver_d *fsdrv;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
-	f = &files[fd];
 	if (offset >= f->size)
 		return 0;
 	if (count > f->size - offset)
@@ -532,15 +515,13 @@ int protect_file(const char *file, int prot)
 void *memmap(int fd, int flags)
 {
 	struct fs_driver_d *fsdrv;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	void *retp = MAP_FAILED;
 	int ret;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return retp;
 
-	f = &files[fd];
-
 	fsdrv = f->fsdev->driver;
 
 	if (fsdrv->memmap)
@@ -558,14 +539,12 @@ EXPORT_SYMBOL(memmap);
 int close(int fd)
 {
 	struct fs_driver_d *fsdrv;
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 	int ret = 0;
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
 
-	f = &files[fd];
-
 	fsdrv = f->fsdev->driver;
 
 	if (fsdrv->close)
@@ -847,13 +826,11 @@ static void stat_inode(struct inode *inode, struct stat *s)
 
 int fstat(int fd, struct stat *s)
 {
-	FILE *f;
+	FILE *f = fd_to_file(fd);
 
-	if (check_fd(fd))
+	if (IS_ERR(f))
 		return -errno;
 
-	f = &files[fd];
-
 	stat_inode(f->f_inode, s);
 
 	return 0;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/6] fs: Drop needless OOM check
  2019-02-26 19:52 [PATCH 1/6] fs: Drop needless OOM check Andrey Smirnov
                   ` (4 preceding siblings ...)
  2019-02-26 19:53 ` [PATCH 6/6] fs: Simplify fd to FILE lookup code Andrey Smirnov
@ 2019-02-27  7:35 ` Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2019-02-27  7:35 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Tue, Feb 26, 2019 at 11:52:58AM -0800, Andrey Smirnov wrote:
> Drop needless OOM check since xzalloc() will never return NULL.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  fs/fs.c | 3 ---
>  1 file changed, 3 deletions(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-02-27  7:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-26 19:52 [PATCH 1/6] fs: Drop needless OOM check Andrey Smirnov
2019-02-26 19:52 ` [PATCH 2/6] fs: ramfs: " Andrey Smirnov
2019-02-26 19:53 ` [PATCH 3/6] fs: Make use of cdev_erase() Andrey Smirnov
2019-02-26 19:53 ` [PATCH 4/6] fs: Make use of cdev_flush() Andrey Smirnov
2019-02-26 19:53 ` [PATCH 5/6] fs: Drop unused code in fstat() Andrey Smirnov
2019-02-26 19:53 ` [PATCH 6/6] fs: Simplify fd to FILE lookup code Andrey Smirnov
2019-02-27  7:35 ` [PATCH 1/6] fs: Drop needless OOM check Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox