LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] proc/fd: Remove the initialization of variables in seq_show()
@ 2020-05-23 15:49 Kaitao Cheng
  0 siblings, 0 replies; 3+ messages in thread
From: Kaitao Cheng @ 2020-05-23 15:49 UTC (permalink / raw)
  To: adobriyan; +Cc: pilgrimtao, linux-kernel, linux-fsdevel, songmuchun

The variables{files, file} will definitely be assigned,
so we don't need to initialize them.

Signed-off-by: Kaitao Cheng <pilgrimtao@gmail.com>
---
 fs/proc/fd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/proc/fd.c b/fs/proc/fd.c
index 81882a13212d..6f95baf44e37 100644
--- a/fs/proc/fd.c
+++ b/fs/proc/fd.c
@@ -19,9 +19,9 @@
 
 static int seq_show(struct seq_file *m, void *v)
 {
-	struct files_struct *files = NULL;
+	struct files_struct *files;
 	int f_flags = 0, ret = -ENOENT;
-	struct file *file = NULL;
+	struct file *file;
 	struct task_struct *task;
 
 	task = get_proc_task(m->private);
-- 
2.20.1


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

* Re: [PATCH] proc/fd: Remove the initialization of variables in seq_show()
  2020-05-24  7:46 Markus Elfring
@ 2020-05-28 12:51 ` Tao pilgrim
  0 siblings, 0 replies; 3+ messages in thread
From: Tao pilgrim @ 2020-05-28 12:51 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-fsdevel, linux-kernel, kernel-janitors, Alexey Dobriyan,
	Muchun Song

> > The variables{files, file} will definitely be assigned,
>
> I find an other specification nicer for these identifiers.
>
>
> > so we don't need to initialize them.
>
> I suggest to recheck programming concerns around the handling
> of the null pointer for the variable “file”.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/proc/fd.c?id=caffb99b6929f41a69edbb5aef3a359bf45f3315#n20
> https://elixir.bootlin.com/linux/v5.7-rc6/source/fs/proc/fd.c#L20

We don't need to initialize the variable “file”.
On line 34, if (files) is true,
{file = fcheck_files(files, fd)} will be executed on line 38.
On line 34, if (files) is flse,
{return ret;} will be executed on line 54, and seq_show() will exit directly.
I don't find the programming concerns around the handling of the null
pointer for the variable “file”.

If you have other suggestions, please elaborate on the details.

--
Yours,
Kaitao Cheng

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

* Re: [PATCH] proc/fd: Remove the initialization of variables in seq_show()
@ 2020-05-24  7:46 Markus Elfring
  2020-05-28 12:51 ` Tao pilgrim
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2020-05-24  7:46 UTC (permalink / raw)
  To: Kaitao Cheng, linux-fsdevel
  Cc: linux-kernel, kernel-janitors, Alexey Dobriyan, Muchun Song

> The variables{files, file} will definitely be assigned,

I find an other specification nicer for these identifiers.


> so we don't need to initialize them.

I suggest to recheck programming concerns around the handling
of the null pointer for the variable “file”.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/proc/fd.c?id=caffb99b6929f41a69edbb5aef3a359bf45f3315#n20
https://elixir.bootlin.com/linux/v5.7-rc6/source/fs/proc/fd.c#L20

Will another imperative wording be preferred for the change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=caffb99b6929f41a69edbb5aef3a359bf45f3315#n151

Regards,
Markus

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-23 15:49 [PATCH] proc/fd: Remove the initialization of variables in seq_show() Kaitao Cheng
2020-05-24  7:46 Markus Elfring
2020-05-28 12:51 ` Tao pilgrim

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git