Re: [PATCH] md: md2: fix an incorrect NULL check on list iterator

From: Xiaomeng Tong
Date: Mon Mar 28 2022 - 03:56:41 EST


> I'd suggest to rephrase the subject to "md: fix an incorrect NULL check
> in md_reload_sb".

Thank you for the suggestion, i will take it in PATCH v2.

> > - if (!rdev || rdev->desc_nr != nr) {
> > + if (!rdev) {
> > pr_warn("%s: %d Could not find rdev with nr %d\n", __func__, __LINE__, nr);
> > return;
> > }
>
> I guess we only need to check desc_nr since rdev should always be valid
> , and IMO the fix tag
> is not necessary.

No. At least from the pr_warn log, the list can be empty or no element found in it.
If this cases happen, the 'rdev' will be an invalid pointer that point to a invalid
struct containning the HEAD '&((mddev)->disks)'. So this fix is necessary.

--
Xiaomeng Tong