mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Andy Shevchenko' <andy.shevchenko@gmail.com>,
	zhangjiao2 <zhangjiao2@cmss.chinamobile.com>
Cc: "wbg@kernel.org" <wbg@kernel.org>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] tools/counter: close fd when exit
Date: Sun, 8 Sep 2024 20:08:23 +0000	[thread overview]
Message-ID: <e1259039a99d4f23958c4380e5c0b11f@AcuMS.aculab.com> (raw)
In-Reply-To: <ZteZiKKsAYmGdu0s@surfacebook.localdomain>

From: Andy Shevchenko
> Sent: 04 September 2024 00:20
> 
> Tue, Sep 03, 2024 at 04:01:21PM +0800, zhangjiao2 kirjoitti:
> > From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> >
> > close fd when exit the program
> 
> Please, mind English grammar and punctuation.
> Also this doesn't state what the problem is.

After all, when the program exits the kernel closes all the files.

> >  		if (ret == -1) {
> >  			fprintf(stderr, "Error adding watches[%d]: %s\n", i,
> >  				strerror(errno));
> > +			close(fd);
> 
> Since fd is not used in the messaging it's better to close it before printing
> anything. Ditto for other cases.

Unless close() decides to change errno...

> 
> ...
> 
> >  		if (ret != sizeof(event_data)) {
> >  			fprintf(stderr, "Failed to read event data\n");
> > +			close(fd);
> 
> >  			return -EIO;
> 
> Side note: This will return garbage to the userspace. Should be
> 
> 			return EIO;

If that is the return value from main() it is equally invalid.
Valid return values are 0..255 but 128..255 are likely to be
interpreted as 'killed by a signal'.
So really you only get 0..127.
Mostly used as 0 => success and 1 => failure.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


      reply	other threads:[~2024-09-08 20:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-03  8:01 zhangjiao2
2024-09-03 23:19 ` Andy Shevchenko
2024-09-08 20:08   ` David Laight [this message]

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=e1259039a99d4f23958c4380e5c0b11f@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wbg@kernel.org \
    --cc=zhangjiao2@cmss.chinamobile.com \
    /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®