From: Martin Peschke Code looks more sane with this little cleanup, although both memcpy() and kfree() are supposed to cope with NULL pointer or zero length respectively. Signed-off-by: Martin Peschke Signed-off-by: Andrew Morton --- lib/statistic.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff -puN lib/statistic.c~statistics-infrastructure-small-cleanup-in-debugfs-write-function lib/statistic.c --- a/lib/statistic.c~statistics-infrastructure-small-cleanup-in-debugfs-write-function +++ a/lib/statistic.c @@ -631,11 +631,13 @@ static ssize_t statistic_write_def(struc if (!larger) return -ENOMEM; larger[*offset + len] = '\0'; - memcpy(larger, seq_priv->w_buf, *offset); + if (seq_priv->w_buf) { + memcpy(larger, seq_priv->w_buf, *offset); + kfree(seq_priv->w_buf); + } if (copy_from_user(larger + *offset, buf, len)) return -EFAULT; *offset += len; - kfree(seq_priv->w_buf); seq_priv->w_buf = larger; seq_priv->w_offset = *offset; return len; _