Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: "Usyskin, Alexander" <alexander.usyskin@intel.com>,
	"De Marchi, Lucas" <lucas.demarchi@intel.com>
Cc: Jani Partanen <jiipee@sotapeli.fi>,
	"intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>,
	"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>
Subject: RE: Possible bug?
Date: Tue, 11 Nov 2025 10:06:50 +0200	[thread overview]
Message-ID: <98df450751f934f3a5c20ec09a08b72ef8fa2763@intel.com> (raw)
In-Reply-To: <CY5PR11MB636652A1A7F88249BD81047DEDCFA@CY5PR11MB6366.namprd11.prod.outlook.com>

On Tue, 11 Nov 2025, "Usyskin, Alexander" <alexander.usyskin@intel.com> wrote:
>> On Mon, Nov 10, 2025 at 03:49:20PM +0200, Jani Nikula wrote:
>> >On Sun, 09 Nov 2025, Jani Partanen <jiipee@sotapeli.fi> wrote:
>> >> Hello, I just got Intel Arc B570. It seems to work fine but every boot I
>> >> get this in dmesg:
>> >>
>> >> [  342.865944] ------------[ cut here ]------------
>> >> [  342.865950] UBSAN: array-index-out-of-bounds in
>> >> drivers/mtd/devices/mtd_intel_dg.c:750:15
>> >> [  342.865954] index 0 is out of range for type '<unknown> [*]'
>> >
>> >Cc: Alexander and linux-mtd.
>> >
>> >It's probably due to struct intel_dg_nvm regions[] member being
>> >__counted_by(nregions) but regions[] is indexed before nregions has been
>> >initialized.
>> 
>> yeah... and we shouldn't silently continue hiding the ENOMEM... Sasha,
>> something like this?
>> 
>
> In general, looks good for me, but I see that we can fill less entries because of
>                 if (!invm->regions[i].name)
>                         continue;
>
> Let's leave 'nvm->nregions = n;' in place, only need to fix the comment.

You have this in place, nregions already accouns for them:

	/* count available regions */
	for (nregions = 0, i = 0; i < INTEL_DG_NVM_REGIONS; i++) {
		if (invm->regions[i].name)
			nregions++;
	}

BR,
Jani.


>
> - - 
> Thanks,
> Sasha
>
>> Lucas De Marchi
>> 
>> ----
>> diff --git a/drivers/mtd/devices/mtd_intel_dg.c
>> b/drivers/mtd/devices/mtd_intel_dg.c
>> index b438ee5aacc34..114e69135b8d9 100644
>> --- a/drivers/mtd/devices/mtd_intel_dg.c
>> +++ b/drivers/mtd/devices/mtd_intel_dg.c
>> @@ -738,6 +738,7 @@ static int intel_dg_mtd_probe(struct auxiliary_device
>> *aux_dev,
>> 
>>   	kref_init(&nvm->refcnt);
>>   	mutex_init(&nvm->lock);
>> +	nvm->nregions = nregions;
>> 
>>   	for (n = 0, i = 0; i < INTEL_DG_NVM_REGIONS; i++) {
>>   		if (!invm->regions[i].name)
>> @@ -745,13 +746,15 @@ static int intel_dg_mtd_probe(struct
>> auxiliary_device *aux_dev,
>> 
>>   		char *name = kasprintf(GFP_KERNEL, "%s.%s",
>>   				       dev_name(&aux_dev->dev), invm-
>> >regions[i].name);
>> -		if (!name)
>> -			continue;
>> +		if (!name) {
>> +			ret = -ENOMEM;
>> +			goto err;
>> +		}
>> +
>>   		nvm->regions[n].name = name;
>>   		nvm->regions[n].id = i;
>>   		n++;
>>   	}
>> -	nvm->nregions = n; /* in case where kasprintf fail */
>> 
>>   	nvm->base = devm_ioremap_resource(device, &invm->bar);
>>   	if (IS_ERR(nvm->base)) {

-- 
Jani Nikula, Intel

  reply	other threads:[~2025-11-11  8:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-08 22:19 Possible bug? Jani Partanen
2025-11-10 13:49 ` Jani Nikula
2025-11-10 18:10   ` Lucas De Marchi
2025-11-11  7:02     ` Usyskin, Alexander
2025-11-11  8:06       ` Jani Nikula [this message]
2025-11-11 10:58         ` Usyskin, Alexander
2025-11-12 14:57           ` Lucas De Marchi

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=98df450751f934f3a5c20ec09a08b72ef8fa2763@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=alexander.usyskin@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jiipee@sotapeli.fi \
    --cc=linux-mtd@lists.infradead.org \
    --cc=lucas.demarchi@intel.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