[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <fa2b3961-8e5d-4d56-9abe-c79a91f961f9@opensource.cirrus.com>
Date: Tue, 4 Feb 2025 15:51:00 -0600
From: Fredrik Treven <ftreven@...nsource.cirrus.com>
To: Charles Keepax <ckeepax@...nsource.cirrus.com>
CC: Simon Trimmer <simont@...nsource.cirrus.com>,
Richard Fitzgerald
<rf@...nsource.cirrus.com>,
<patches@...nsource.cirrus.com>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/7] firmware: cs_dsp: Check for valid num_regs in
cs_dsp_wseq_multi_write()
On 2/4/25 04:06, Charles Keepax wrote:
> On Fri, Jan 31, 2025 at 01:56:33PM -0600, Fred Treven wrote:
>> If a value of 0 or below is passed into cs_dsp_wseq_multi_write()
>> the function will never enter its for loop.
>>
>> Verify that num_regs passed into the function is valid
>> and throw a user-visible error if not.
>>
>> Signed-off-by: Fred Treven <ftreven@...nsource.cirrus.com>
>> ---
>> drivers/firmware/cirrus/cs_dsp.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/firmware/cirrus/cs_dsp.c b/drivers/firmware/cirrus/cs_dsp.c
>> index 56315b0b5583..aacf6960d1ea 100644
>> --- a/drivers/firmware/cirrus/cs_dsp.c
>> +++ b/drivers/firmware/cirrus/cs_dsp.c
>> @@ -3743,6 +3743,11 @@ int cs_dsp_wseq_multi_write(struct cs_dsp *dsp, struct cs_dsp_wseq *wseq,
>> {
>> int i, ret;
>>
>> + if (num_regs <= 0) {
>> + cs_dsp_err(dsp, "Invalid number of regs: %d\n", num_regs);
>> + return -EINVAL;
>> + }
>> +
>
> This feels a little defensive, do we really need to check for
> this? Normally num_regs is going to come from an ARRAY_SIZE or
> something.
>
> Thanks,
> Charles
I see your point. The reason I wanted to add this, though, was because I fell
into the trap myself by mistakenly swapping the op_code input and the num_regs
input.
It then became very difficult to track down the mistake because there was no
condition to catch it in place.
If you feel strongly that I should drop this patch then I am okay with doing so.
Best regards,
Fred
Powered by blists - more mailing lists