diff mbox series

mtd: handle ubi_attach race condition

Message ID 20240408065913.40798-1-james.hilliard1@gmail.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series mtd: handle ubi_attach race condition | expand

Commit Message

James Hilliard April 8, 2024, 6:59 a.m. UTC
If ubi_attach was called while the attachment was already in progress
we may get an EEXIST error.

If this happens get the dev_num with mtd_num2ubi_dev and do not keep
attempting to attach.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 corelib/mtd-interface.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

James Hilliard April 18, 2024, 6:04 p.m. UTC | #1
I noticed this is showing up as "Changes Requested" in patchwork, was there
something that needed to be changed here?

On Mon, Apr 8, 2024 at 12:59 AM James Hilliard <james.hilliard1@gmail.com>
wrote:

> If ubi_attach was called while the attachment was already in progress
> we may get an EEXIST error.
>
> If this happens get the dev_num with mtd_num2ubi_dev and do not keep
> attempting to attach.
>
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
>  corelib/mtd-interface.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c
> index 90fc6dc..c897968 100644
> --- a/corelib/mtd-interface.c
> +++ b/corelib/mtd-interface.c
> @@ -379,6 +379,9 @@ static void scan_ubi_partitions(int mtd)
>         do {
>                 err = ubi_attach(libubi, DEFAULT_CTRL_DEV, &mtd_info->req);
>                 if (err) {
> +                       /* Handle race condition where MTD was already
> being attached. */
> +                       if (errno == EEXIST && !mtd_num2ubi_dev(libubi,
> mtd, &mtd_info->req.dev_num))
> +                               break;
>                         if (mtd_info->has_ubi && !tryattach) {
>                                 TRACE("cannot attach mtd%d ..try erasing",
> mtd);
>                                 if (flash_erase(mtd)) {
> --
> 2.34.1
>
>
Stefano Babic April 18, 2024, 8:32 p.m. UTC | #2
Hi James,

On 18.04.24 20:04, James Hilliard wrote:
> I noticed this is showing up as "Changes Requested" in patchwork, was
> there something that needed to be changed here?
>

I should erroneously set the state, thanks for noting this.

Best regards,
Stefano

> On Mon, Apr 8, 2024 at 12:59 AM James Hilliard
> <james.hilliard1@gmail.com <mailto:james.hilliard1@gmail.com>> wrote:
>
>     If ubi_attach was called while the attachment was already in progress
>     we may get an EEXIST error.
>
>     If this happens get the dev_num with mtd_num2ubi_dev and do not keep
>     attempting to attach.
>
>     Signed-off-by: James Hilliard <james.hilliard1@gmail.com
>     <mailto:james.hilliard1@gmail.com>>
>     ---
>       corelib/mtd-interface.c | 3 +++
>       1 file changed, 3 insertions(+)
>
>     diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c
>     index 90fc6dc..c897968 100644
>     --- a/corelib/mtd-interface.c
>     +++ b/corelib/mtd-interface.c
>     @@ -379,6 +379,9 @@ static void scan_ubi_partitions(int mtd)
>              do {
>                      err = ubi_attach(libubi, DEFAULT_CTRL_DEV,
>     &mtd_info->req);
>                      if (err) {
>     +                       /* Handle race condition where MTD was
>     already being attached. */
>     +                       if (errno == EEXIST &&
>     !mtd_num2ubi_dev(libubi, mtd, &mtd_info->req.dev_num))
>     +                               break;
>                              if (mtd_info->has_ubi && !tryattach) {
>                                      TRACE("cannot attach mtd%d ..try
>     erasing", mtd);
>                                      if (flash_erase(mtd)) {
>     --
>     2.34.1
>
> --
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swupdate+unsubscribe@googlegroups.com
> <mailto:swupdate+unsubscribe@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/swupdate/CADvTj4qZVzZUVmtkZin6E205TYQuesNGp%3D7Fe48SiPWtRWZCmw%40mail.gmail.com <https://groups.google.com/d/msgid/swupdate/CADvTj4qZVzZUVmtkZin6E205TYQuesNGp%3D7Fe48SiPWtRWZCmw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
diff mbox series

Patch

diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c
index 90fc6dc..c897968 100644
--- a/corelib/mtd-interface.c
+++ b/corelib/mtd-interface.c
@@ -379,6 +379,9 @@  static void scan_ubi_partitions(int mtd)
 	do {
 		err = ubi_attach(libubi, DEFAULT_CTRL_DEV, &mtd_info->req);
 		if (err) {
+			/* Handle race condition where MTD was already being attached. */
+			if (errno == EEXIST && !mtd_num2ubi_dev(libubi, mtd, &mtd_info->req.dev_num))
+				break;
 			if (mtd_info->has_ubi && !tryattach) {
 				TRACE("cannot attach mtd%d ..try erasing", mtd);
 				if (flash_erase(mtd)) {