[PATCH] mtd: ubi: Fix race condition between ubi device creation and udev

Richard Weinberger richard.weinberger at gmail.com
Thu Jul 21 04:42:59 PDT 2016


Iosif,

On Thu, Jul 21, 2016 at 4:07 AM, Iosif Harutyunov
<iharutyunov at sonicwall.com> wrote:
>
> While implementing udev rules for UBI device I ran into the problem when udev would
> ignore UBI rules I created to process attachment of volume. Interestingly, when I trigger
> udev ubi subsystem "change" event manually after the attachment, rules would work just fine.
>
> I traced problem down to UBI sysfs processing, which turned out to be racing condition.
> See patch below to address the problem.

The symptom is that /dev/ubiX_Y appeared, udev got a notification but
reading sysfs
attributes always failed with -ENODEV?

How did you debug this? Sounds like a painful issue to debug. ;-\

> Thanks.
> Iosif,_
>
> Signed-off-by: Iosif Harutyunov <iharutyunov at sonicwall.com>
> ---
> Once ubi is attached, make sure ubi_devices[] is initialized early before being
> used in the dev_attribute_show().
>
> This is to prevent race condition between udev ubi rules processing and ubi device
> creation, which manifests itself ignoring udev ATTR rules.
>
> ---
>  drivers/mtd/ubi/build.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
> index ef36182..e6117d7 100644
> --- a/drivers/mtd/ubi/build.c
> +++ b/drivers/mtd/ubi/build.c
> @@ -986,6 +986,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
>                 goto out_free;
>         }
>
> +       ubi_devices[ubi_num] = ubi;
> +

Okay, the fix is to make sure that ubi_devices[ubi_num] is set before
we init sysfs.
Why do you add this before the autoresize code?
I'd expect it right before uif_init().

-- 
Thanks,
//richard



More information about the linux-mtd mailing list