mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Dan Carpenter <dan.carpenter@linaro.org>,
	Greg KH <gregkh@linuxfoundation.org>
Cc: Prasad Pandit <pj.pandit@yahoo.in>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Dwaipayan Ray <dwaipayanray1@gmail.com>,
	 Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	Andy Whitcroft <apw@canonical.com>
Subject: Re: [PATCH] checkpatch: error if file terminates without a new-line
Date: Tue, 16 Apr 2024 02:55:11 -0700	[thread overview]
Message-ID: <a582c379f1bc2bc0d16b46ece9211bac40b4b7cf.camel@perches.com> (raw)
In-Reply-To: <edf23b1b-303a-46eb-b455-8c766c84ddf1@moroto.mountain>

On Tue, 2024-04-16 at 11:59 +0300, Dan Carpenter wrote:
> On Tue, Apr 16, 2024 at 10:48:27AM +0200, Greg KH wrote:
> > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > > index 9c4c4a61bc83..df34c0709410 100755
> > > --- a/scripts/checkpatch.pl
> > > +++ b/scripts/checkpatch.pl
> > > @@ -2795,6 +2795,13 @@ sub process {
> > >             $is_patch = 1;
> > >         }
> > > 
> > > +# check if patch terminates file without a new line (\n)
> > > +        if ($line =~ /^\\ No newline at end of file$/
> > > +            and $rawlines[$linenr - 2] =~ /^\+.*$/) {
> > > +            ERROR("NOEOL_FILE",
> > > +                  "patch terminates file without a new line (\\n).");
> > > +        }
> > 
> > Why is this a problem?  files without a new line should not cause
> > problems with a compiler, right?  You don't have a justification for why
> > this change needs to be checked for anywhere.
> > 
> 
> I gave him such a good reason too...  It breaks `cat file.c`.  Plus, it
> looks weird in `git log -p` because it has a "No newline at the end of
> file" comment.
> 
> regards,
> dan carpenter
> 
> diff --git a/test.c b/test.c
> new file mode 100644
> index 000000000000..d808cac2d962
> --- /dev/null
> +++ b/test.c
> @@ -0,0 +1,12 @@
> +#include <stdio.h>
> +#include <stdbool.h>
> +#include "check_debug.h"
> +
> +void kfree(int *p);
> +
> +int *p;
> +int main(void)
> +{
> +       kfree(p);
> +       *p = 1;
> +}
> \ No newline at end of file
> 
> commit f4a997924122d0094675c897a220371f0a129d90
> 

There's an existing check for this.
I believe it at least used to work.
Fix that instead.

# check for adding lines without a newline.
		if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
			if (WARN("MISSING_EOF_NEWLINE",
			         "adding a line without newline at end of file\n" . $herecurr) &&
			    $fix) {
				fix_delete_line($fixlinenr+1, "No newline at end of file");
			}
		}


  reply	other threads:[~2024-04-16 10:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240330033858.3272184-1-ppandit@redhat.com>
2024-04-16  7:04 ` Prasad Pandit
2024-04-16  8:48   ` Greg KH
2024-04-16  8:59     ` Dan Carpenter
2024-04-16  9:55       ` Joe Perches [this message]
2024-04-17  6:36         ` Prasad Pandit

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=a582c379f1bc2bc0d16b46ece9211bac40b4b7cf.camel@perches.com \
    --to=joe@perches.com \
    --cc=apw@canonical.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dwaipayanray1@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=pj.pandit@yahoo.in \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®