LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Tom Zanussi <tom.zanussi@linux.intel.com>
To: josh@joshtriplett.org
Cc: linux-kernel@vger.kernel.org, Tom Zanussi <tom.zanussi@linux.intel.com>
Subject: [PATCH 04/10] drivers/char: Support compiling out /dev/null
Date: Fri, 23 Jan 2015 12:37:10 -0600 [thread overview]
Message-ID: <331a37ea64bd58f9d66869fd2ccd8034ab1566d6.1422035184.git.tom.zanussi@linux.intel.com> (raw)
In-Reply-To: <cover.1422035184.git.tom.zanussi@linux.intel.com>
In-Reply-To: <cover.1422035184.git.tom.zanussi@linux.intel.com>
Some embedded systems with tightly controlled userspace have no use
for /dev/null, and could benefit from the size savings gained by
omitting it. Add a new EMBEDDED config option to disable it.
write_null() and aio_write_null() are shared between /dev/null and
/dev/zero; making it __maybe_unused prevents them from emitting
warnings if both devices are compiled out, while avoiding ugly
compound ifdefs. Similarly for null_lseek, shared between /dev/null,
/dev/zero, and /dev/full.
bloat-o-meter (based on tinyconfig):
add/remove: 0/5 grow/shrink: 0/0 up/down: 0/-150 (-150)
function old new delta
read_null 3 - -3
aio_read_null 3 - -3
pipe_to_null 4 - -4
splice_write_null 24 - -24
null_fops 116 - -116
bloat-o-meter showing the difference between only CONFIG_DEVZERO and
CONFIG_DEVFULL off and both those plus CONFIG_DEVNULL off:
add/remove: 0/8 grow/shrink: 0/0 up/down: 0/-196 (-196)
function old new delta
write_null 3 - -3
read_null 3 - -3
aio_read_null 3 - -3
pipe_to_null 4 - -4
aio_write_null 18 - -18
splice_write_null 24 - -24
null_lseek 25 - -25
null_fops 116 - -116
So with DEVZERO also configured out, we see the shared write_null,
aio_write_null, and null_lseek drop out.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
drivers/char/Kconfig | 10 ++++++++++
drivers/char/mem.c | 35 ++++++++++++++++++++++-------------
2 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 5a6c060..17f6ddf 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -36,6 +36,16 @@ config DEVMEM
disabled on systems that will never use either, such as many
embedded systems. When in doubt, say "Y".
+config DEVNULL
+ bool "/dev/null virtual device support" if EMBEDDED
+ depends on DEVMEM_BASE
+ default y
+ help
+ Say Y here if you want to support the /dev/null device. The
+ /dev/null device is used by many programs, but some embedded
+ systems with strictly controlled userspace may not need it.
+ When in doubt, say "Y".
+
config SGI_SNSC
bool "SGI Altix system controller communication support"
depends on (IA64_SGI_SN2 || IA64_GENERIC)
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 5944d87..25d6f5b 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -593,30 +593,19 @@ static ssize_t write_port(struct file *file, const char __user *buf,
}
#endif
+#ifdef CONFIG_DEVNULL
static ssize_t read_null(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
return 0;
}
-static ssize_t write_null(struct file *file, const char __user *buf,
- size_t count, loff_t *ppos)
-{
- return count;
-}
-
static ssize_t aio_read_null(struct kiocb *iocb, const struct iovec *iov,
unsigned long nr_segs, loff_t pos)
{
return 0;
}
-static ssize_t aio_write_null(struct kiocb *iocb, const struct iovec *iov,
- unsigned long nr_segs, loff_t pos)
-{
- return iov_length(iov, nr_segs);
-}
-
static int pipe_to_null(struct pipe_inode_info *info, struct pipe_buffer *buf,
struct splice_desc *sd)
{
@@ -628,6 +617,21 @@ static ssize_t splice_write_null(struct pipe_inode_info *pipe, struct file *out,
{
return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_null);
}
+#endif
+
+static ssize_t __maybe_unused write_null(struct file *file,
+ const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ return count;
+}
+
+static ssize_t __maybe_unused aio_write_null(struct kiocb *iocb,
+ const struct iovec *iov,
+ unsigned long nr_segs, loff_t pos)
+{
+ return iov_length(iov, nr_segs);
+}
static ssize_t read_iter_zero(struct kiocb *iocb, struct iov_iter *iter)
{
@@ -669,7 +673,8 @@ static ssize_t write_full(struct file *file, const char __user *buf,
* can fopen() both devices with "a" now. This was previously impossible.
* -- SRB.
*/
-static loff_t null_lseek(struct file *file, loff_t offset, int orig)
+static loff_t __maybe_unused null_lseek(struct file *file, loff_t offset,
+ int orig)
{
return file->f_pos = 0;
}
@@ -742,6 +747,7 @@ static const struct file_operations kmem_fops = {
};
#endif
+#ifdef CONFIG_DEVNULL
static const struct file_operations null_fops = {
.llseek = null_lseek,
.read = read_null,
@@ -750,6 +756,7 @@ static const struct file_operations null_fops = {
.aio_write = aio_write_null,
.splice_write = splice_write_null,
};
+#endif
#ifdef CONFIG_DEVPORT
static const struct file_operations port_fops = {
@@ -798,7 +805,9 @@ static const struct memdev {
#ifdef CONFIG_DEVKMEM
[2] = { "kmem", 0, &kmem_fops, &directly_mappable_cdev_bdi },
#endif
+#ifdef CONFIG_DEVNULL
[3] = { "null", 0666, &null_fops, NULL },
+#endif
#ifdef CONFIG_DEVPORT
[4] = { "port", 0, &port_fops, NULL },
#endif
--
1.9.3
next prev parent reply other threads:[~2015-01-23 18:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-23 18:37 [PATCH 00/10] tinification: Make memory-access char devices optional Tom Zanussi
2015-01-23 18:37 ` [PATCH 01/10] drivers/char: Support compiling out memory-access char devices Tom Zanussi
2015-01-23 18:37 ` [PATCH 02/10] drivers/char: Support compiling out /dev/mem Tom Zanussi
2015-01-23 18:37 ` [PATCH 03/10] drivers/char: Support compiling out /dev/port Tom Zanussi
2015-01-23 18:37 ` Tom Zanussi [this message]
2015-01-23 18:37 ` [PATCH 05/10] drivers/char: Support compiling out /dev/zero Tom Zanussi
2015-01-28 21:07 ` Pavel Machek
2015-01-28 21:51 ` josh
2015-01-28 21:52 ` Pavel Machek
2015-01-28 23:20 ` Tom Zanussi
2015-01-31 23:08 ` Josh Triplett
2015-01-23 18:37 ` [PATCH 06/10] drivers/char: Support compiling out /dev/full Tom Zanussi
2015-01-23 18:37 ` [PATCH 07/10] drivers/char: Support compiling out /dev/random Tom Zanussi
2015-01-23 18:37 ` [PATCH 08/10] drivers/char: Support compiling out /dev/urandom Tom Zanussi
2015-01-23 18:37 ` [PATCH 09/10] drivers/char: Support compiling out /dev/kmsg Tom Zanussi
2015-01-23 18:37 ` [PATCH 10/10] drivers/char: Support compiling out the getrandom(2) syscall Tom Zanussi
2015-01-23 19:46 ` Theodore Ts'o
2015-01-23 20:04 ` Tom Zanussi
2015-01-23 22:30 ` josh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=331a37ea64bd58f9d66869fd2ccd8034ab1566d6.1422035184.git.tom.zanussi@linux.intel.com \
--to=tom.zanussi@linux.intel.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--subject='Re: [PATCH 04/10] drivers/char: Support compiling out /dev/null' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).