linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Elder <elder@linaro.org>
To: Leon Romanovsky <leon@kernel.org>
Cc: davem@davemloft.net, kuba@kernel.org, bjorn.andersson@linaro.org,
	evgreen@chromium.org, cpratapa@codeaurora.org, elder@kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 4/4] net: ipa: activate some commented assertions
Date: Fri, 19 Mar 2021 10:32:50 -0500	[thread overview]
Message-ID: <69647805-7ace-442d-2268-aa7c4800ab6e@linaro.org> (raw)
In-Reply-To: <YFTAn7tHBAG2PO78@unreal>

On 3/19/21 10:17 AM, Leon Romanovsky wrote:
>>>> @@ -212,7 +213,7 @@ static inline u32 ipa_reg_bcr_val(enum ipa_version version)
>>>>    			BCR_HOLB_DROP_L2_IRQ_FMASK |
>>>>    			BCR_DUAL_TX_FMASK;
>>>> -	/* assert(version != IPA_VERSION_4_5); */
>>>> +	ipa_assert(NULL, version != IPA_VERSION_4_5);
>>> This assert will fire for IPA_VERSION_4_2, I doubt that this is
>>> something you want.
>> No, it will only fail if version == IPA_VERSION_4_5.
>> The logic of an assertion is the opposite of BUG_ON().
>> It fails only if the asserted condition yields false.
> ok, this ipa_reg_bcr_val() is called in only one place and has a
> protection from IPA_VERSION_4_5, why don't you code it at the same
> .c file instead of adding useless assert?

As I mentioned in my other message, the purpose of an
assertion is *communicating with the reader*.  The
fact that an assertion may expand to code that ensures
the assertion is true is secondary.

This particular assertion says that the version will never
be 4.5.  While looking at this function, you don't need to
see if the caller ensures that, the assertion *tells* you.

Whether an assertion is warranted is really subjective.
You may not appreciate the value of that, but I do.

					-Alex

  reply	other threads:[~2021-03-19 15:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-19  4:29 [PATCH net-next 0/4] net: ipa: fix validation Alex Elder
2021-03-19  4:29 ` [PATCH net-next 1/4] net: ipa: fix init header command validation Alex Elder
2021-03-19  4:29 ` [PATCH net-next 2/4] net: ipa: fix IPA validation Alex Elder
2021-03-19  4:29 ` [PATCH net-next 3/4] net: ipa: introduce ipa_assert() Alex Elder
2021-03-19  4:55   ` Leon Romanovsky
2021-03-19 12:38     ` Alex Elder
2021-03-19 15:32       ` Leon Romanovsky
2021-03-19 16:01         ` Alex Elder
2021-03-19 18:20     ` Andrew Lunn
2021-03-19  4:29 ` [PATCH net-next 4/4] net: ipa: activate some commented assertions Alex Elder
2021-03-19  5:00   ` Leon Romanovsky
2021-03-19 12:40     ` Alex Elder
2021-03-19 15:17       ` Leon Romanovsky
2021-03-19 15:32         ` Alex Elder [this message]
2021-03-19 18:32   ` Andrew Lunn
2021-03-19 21:18     ` Alex Elder
2021-03-19 21:30       ` Andrew Lunn
2021-03-20 13:24 ` [PATCH net-next 0/4] net: ipa: fix validation Alex Elder
2021-03-20 14:23   ` Alex Elder

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=69647805-7ace-442d-2268-aa7c4800ab6e@linaro.org \
    --to=elder@linaro.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=cpratapa@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=elder@kernel.org \
    --cc=evgreen@chromium.org \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).