All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Yury Norov <yury.norov@gmail.com>
Cc: Alexander Potapenko <glider@google.com>,
	catalin.marinas@arm.com, will@kernel.org, pcc@google.com,
	andreyknvl@gmail.com, linux@rasmusvillemoes.dk,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, eugenis@google.com
Subject: Re: [v2 3/5] arm64: mte: implement CONFIG_ARM64_MTE_COMP
Date: Fri, 14 Jul 2023 11:01:34 +0300	[thread overview]
Message-ID: <ZLEA3oxst2FBDWhC@smile.fi.intel.com> (raw)
In-Reply-To: <ZLBQCFbBOaBUTQmB@yury-ThinkPad>

On Thu, Jul 13, 2023 at 12:27:15PM -0700, Yury Norov wrote:

...

> > > +	void *storage = ea0_storage(handle);
> > > +	int size = ea0_storage_size(handle);

> > > +	if (!handle || !storage)
> > > +		return;
> > 
> > You use handle before this check. Haven't you run static analysers?
> 
> This approach is called 'defensive programming' as I learned from
> previous iteration.

No, this approach called "let compiler optimize the check away". :-)

When compiler sees something like

	TYPE bar = MACRO(foo); // FUNC(foo);

	if (!foo)
		blalblabla;

the conditional can be eliminated as the optimizer thinks the way "okay,
developer already _used_ the foo in some code, it means it can't not be NULL,
let's drop a dead code".

(Yes, I know what defensive programming means and we actually quite rarely
 use it in the kernel for the internal APIs)

-- 
With Best Regards,
Andy Shevchenko



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Yury Norov <yury.norov@gmail.com>
Cc: Alexander Potapenko <glider@google.com>,
	catalin.marinas@arm.com, will@kernel.org, pcc@google.com,
	andreyknvl@gmail.com, linux@rasmusvillemoes.dk,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, eugenis@google.com
Subject: Re: [v2 3/5] arm64: mte: implement CONFIG_ARM64_MTE_COMP
Date: Fri, 14 Jul 2023 11:01:34 +0300	[thread overview]
Message-ID: <ZLEA3oxst2FBDWhC@smile.fi.intel.com> (raw)
In-Reply-To: <ZLBQCFbBOaBUTQmB@yury-ThinkPad>

On Thu, Jul 13, 2023 at 12:27:15PM -0700, Yury Norov wrote:

...

> > > +	void *storage = ea0_storage(handle);
> > > +	int size = ea0_storage_size(handle);

> > > +	if (!handle || !storage)
> > > +		return;
> > 
> > You use handle before this check. Haven't you run static analysers?
> 
> This approach is called 'defensive programming' as I learned from
> previous iteration.

No, this approach called "let compiler optimize the check away". :-)

When compiler sees something like

	TYPE bar = MACRO(foo); // FUNC(foo);

	if (!foo)
		blalblabla;

the conditional can be eliminated as the optimizer thinks the way "okay,
developer already _used_ the foo in some code, it means it can't not be NULL,
let's drop a dead code".

(Yes, I know what defensive programming means and we actually quite rarely
 use it in the kernel for the internal APIs)

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-07-14  8:02 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-13 12:57 [v2 0/5] Implement MTE tag compression for swapped pages Alexander Potapenko
2023-07-13 12:57 ` Alexander Potapenko
2023-07-13 12:57 ` [v2 1/5] lib/bitmap: add bitmap_{set,get}_value_unaligned() Alexander Potapenko
2023-07-13 12:57   ` Alexander Potapenko
2023-07-13 17:28   ` Andy Shevchenko
2023-07-13 17:28     ` Andy Shevchenko
2023-07-13 18:05     ` Alexander Potapenko
2023-07-13 18:05       ` Alexander Potapenko
2023-07-14  8:04       ` Andy Shevchenko
2023-07-14  8:04         ` Andy Shevchenko
2023-07-14 11:19         ` William Breathitt Gray
2023-07-14 11:19           ` William Breathitt Gray
2023-07-14 11:28           ` Andy Shevchenko
2023-07-14 11:28             ` Andy Shevchenko
2023-07-14 12:07             ` Alexander Potapenko
2023-07-14 12:07               ` Alexander Potapenko
2023-07-14 12:30               ` Andy Shevchenko
2023-07-14 12:30                 ` Andy Shevchenko
2023-07-13 12:57 ` [v2 2/5] lib/test_bitmap: add tests for bitmap_{set,get}_value_unaligned Alexander Potapenko
2023-07-13 12:57   ` Alexander Potapenko
2023-07-13 12:57 ` [v2 3/5] arm64: mte: implement CONFIG_ARM64_MTE_COMP Alexander Potapenko
2023-07-13 12:57   ` Alexander Potapenko
2023-07-13 16:37   ` Alexander Potapenko
2023-07-13 16:37     ` Alexander Potapenko
2023-07-13 17:23   ` Andy Shevchenko
2023-07-13 17:23     ` Andy Shevchenko
2023-07-13 19:27     ` Yury Norov
2023-07-13 19:27       ` Yury Norov
2023-07-14  8:01       ` Andy Shevchenko [this message]
2023-07-14  8:01         ` Andy Shevchenko
2023-07-14  9:25     ` Alexander Potapenko
2023-07-14  9:25       ` Alexander Potapenko
2023-07-14 10:47       ` Andy Shevchenko
2023-07-14 10:47         ` Andy Shevchenko
2023-07-14 11:17         ` Alexander Potapenko
2023-07-14 11:17           ` Alexander Potapenko
2023-07-13 12:57 ` [v2 4/5] arm64: mte: add a test for MTE tags compression Alexander Potapenko
2023-07-13 12:57   ` Alexander Potapenko
2023-07-13 12:57 ` [v2 5/5] arm64: mte: add compression support to mteswap.c Alexander Potapenko
2023-07-13 12:57   ` Alexander Potapenko

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=ZLEA3oxst2FBDWhC@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=andreyknvl@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=eugenis@google.com \
    --cc=glider@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pcc@google.com \
    --cc=will@kernel.org \
    --cc=yury.norov@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.