From patchwork Fri Apr 22 23:59:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1621284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=OZkKIKo8; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::539; helo=mail-pg1-x539.google.com; envelope-from=swupdate+bncbcwivbv7sugrb7ecrwjqmgqe5gx557q@googlegroups.com; receiver=) Received: from mail-pg1-x539.google.com (mail-pg1-x539.google.com [IPv6:2607:f8b0:4864:20::539]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KlWcK2kQRz9s3q for ; Sat, 23 Apr 2022 10:00:00 +1000 (AEST) Received: by mail-pg1-x539.google.com with SMTP id q13-20020a638c4d000000b003821725ad66sf5806590pgn.23 for ; Fri, 22 Apr 2022 16:59:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1650671997; cv=pass; d=google.com; s=arc-20160816; b=NCHuD+EupQWECHnVS84fzn29+0Gxo5logu+dSlnABr1PZI40cHvE9uol3matSNv4d5 U34fHMCxSVs5jf0Z0x6MLPRU8XhduWdrfUmHhzIN0wp4hX452zGB33kWAcJz2oEDWuFR y2lLMdYdcHHxlVb82irM2bEHi9KvleaNMGtd8+3kJrObW55b5r8wtZDKY1WE5v0lc9Gq p7dPxRsBHO7jmyo6KgCWIWHXz0kfW6WofEQoesvX4a6y+biZ3VStJVu0cgLnCcsuLqtd lPRUdCPzGhHROkIew2o5URmscrz3wNSWOCMoE+R6Q8nTN7yCRpFtgTi9OCLUlBY2513W 16ZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=e9qebpFWshdGvo3tweJxQepIlzPo7LUL6LlbmZxDK08=; b=iHD6y4rppEWrhDkDD9SupkghonNGcuV2ijaldesFjBfBJrrCSPIz5I7b/Fv4qkY43r tRhGHfoGdDcQ1di3xKqUctCF8Jk+rVIwTrnDdGLRFTigns5dmLvDvKTbEfeiuWKKgfyw NENVqqmCL2UWQFo/oDix0PEVbidHa0Cgq+7yrmviTzkWC17WhZKRsNpID0j/XXf+FeiZ mejDuvzQVHeIA1PpjhVXogtAExkBEPhTDHvARXQ+ydZozYPORmrzYhiYjO89hvZaFJK3 y113ScvsPCuI5k6Wm0EY5KKbjnp1wBGv21UrbqUShY9rkbksU4rIbHys8m3xsRc4VAgS iDiQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=e9qebpFWshdGvo3tweJxQepIlzPo7LUL6LlbmZxDK08=; b=OZkKIKo8U6Dlk/hZIQwSCT1HT9IvalZWpUDS43kiRpOWLjeeJBHKQUB6Y5JxwaYHTB mJ8kCTxw4yhDUtCHN0ER7PIhSg1pwEL/lQvoI0JEHnCe3+ft/qObIoHdR8B5mwloLrTE Fq6lx/CY1wcsaUBfN2WM2fuYAusaZuMdpTkgf3Xd8UF6xVwYnpaw1y7YoxL8oVu1E1wf 2AiCk45aQ+oqSHeQhghaBX5mJTS6pQ4fPMLEtWp2g4s4YljLfvcxT9CzvpqCdHr6pNk1 adbaNkIwrhifuzgHP/IBcpmlY+RpAbqGJrjTzEEJwTpXpz8yPk/DCk9UBvdMGDva2b+f T3RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=e9qebpFWshdGvo3tweJxQepIlzPo7LUL6LlbmZxDK08=; b=BppfSxrmUYNZ8MUvq6OzZaODWhnIn0q8jo1RblyrlRqQlLoOR8JiQB5ws/3kBYEzz5 kQ04Fn8GkWaDJgg4deNrEyE2Dkhno8bxfLvifClkqV6YDK/U4lDyt8CgLcnbchigp9/x z0rKebL6UMkuAJpWahtex0R/FIwtZJE9HcSVvvQrPA5YUhCkvujhOeAB5Gt19f3h5Jm3 O6rIFZmxbAIRkvnNNeSQLtTJsYBCbPgY2CoOvnClH2QCBfB/ZTbZlcCsZy+WEkTkyj6r M2wHlR0u7alTsEkwzac1caHsnB28kGEw+w/zv9DAD3YZDo/7v+9NT31n6/E9THifv9X+ t3yw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM532LPllRAMTvqY1E9O57km5szpZF1H1lnsR+C0iaMMXPRgAtZvPl LuyUkLalwsbceEBscqm8itQ= X-Google-Smtp-Source: ABdhPJzm/wRf3XM2inh//TfoIJ8R1iH2/moZ8WJwZ2rbPBRgnIGh+ysC2Yos9Ks5Jf1Wra9tjM/X6Q== X-Received: by 2002:a05:6a00:1988:b0:4fa:c15d:190d with SMTP id d8-20020a056a00198800b004fac15d190dmr7376394pfl.44.1650671996544; Fri, 22 Apr 2022 16:59:56 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:90b:4cca:b0:1d5:7c21:7e07 with SMTP id nd10-20020a17090b4cca00b001d57c217e07ls6275037pjb.2.gmail; Fri, 22 Apr 2022 16:59:55 -0700 (PDT) X-Received: by 2002:a17:902:b286:b0:15b:335b:53e6 with SMTP id u6-20020a170902b28600b0015b335b53e6mr6937299plr.169.1650671995852; Fri, 22 Apr 2022 16:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650671995; cv=none; d=google.com; s=arc-20160816; b=UDxczy7uQDgEM12G2JCcEdn/r+aguofF3VWv6Dr7OliVDkcQMdjwebIkJ7l/GfcNAH gpdFa9JVMl+nk5/mNrXGuUWAqxugFIiH5FaokOS8IS7hqaFjvt5mpm0XVoDmpElste77 Cy09a0mwXAYAico/jMCq2E8ZVNhMWhTZT1aioToM4FDYE6pW7kqLeaSjDt7hmW8HxTlL lPj5xFxvQbR2vv6JCP8tjlHElvhGl8xOajytAEaZfXDEX5a8PGF3lOjfVE10u32y/4zz rmGI3v00ux4NLDEsyXzIqU05c+155sd1zvYelhpkKfeA4TdKHk/sGuyO2kJrtbtWDm4N hjEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Lt71Vl9sflgMefitFLnTUvcxMpUbhI02wC0QS6Dx6lw=; b=Yu/+3TA5uf9jFRqdrBKoP59B71XWx4luH3shF10bvQ14Of8qifcXskQetq6DQWZk9U gMTQwd4q5GiSTT4d8LJwqzzoIMi6hIQ+U1eLSm1SvtM9UZIz2GhCDPKNps3KK1IuiCkF aSyEkwp81F1QEIcP81lP5hC5YcmUA/IjCDm5jDAfqzaynehCDrJj1KzpRESMQJk+RTE+ gidlGAKsjA2ZRV21ZJR1AQBhfY/1RzijfmGGhM3f041pUGJmu9Qrawl/wbp7deDd/fL2 ltIjgInQFd5vfRN5fkGwPCT/B1rluDdI6WTRLbo9Ykk7L7Q/YSonocNZRiohyKjLHYmT A+ug== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTP id hk1-20020a17090b224100b001c69d267568si938733pjb.0.2022.04.22.16.59.55 for ; Fri, 22 Apr 2022 16:59:55 -0700 (PDT) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id 9D61820D57 for ; Sat, 23 Apr 2022 08:59:54 +0900 (JST) Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by gw2.atmark-techno.com (Postfix) with ESMTPS id 8AB8F20D57 for ; Sat, 23 Apr 2022 08:59:54 +0900 (JST) Received: by mail-pl1-f200.google.com with SMTP id z5-20020a170902ccc500b0015716eaec65so5571281ple.14 for ; Fri, 22 Apr 2022 16:59:54 -0700 (PDT) X-Received: by 2002:a17:90a:410a:b0:1cb:a279:6679 with SMTP id u10-20020a17090a410a00b001cba2796679mr18837210pjf.211.1650671993419; Fri, 22 Apr 2022 16:59:53 -0700 (PDT) X-Received: by 2002:a17:90a:410a:b0:1cb:a279:6679 with SMTP id u10-20020a17090a410a00b001cba2796679mr18837196pjf.211.1650671993207; Fri, 22 Apr 2022 16:59:53 -0700 (PDT) Received: from pc-0115 (162.198.187.35.bc.googleusercontent.com. [35.187.198.162]) by smtp.gmail.com with ESMTPSA id u12-20020a62d44c000000b0050d17e069f2sm369770pfl.10.2022.04.22.16.59.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2022 16:59:51 -0700 (PDT) Received: from martinet by pc-0115 with local (Exim 4.95) (envelope-from ) id 1ni3Bm-00BmZT-8l; Sat, 23 Apr 2022 08:59:50 +0900 From: Dominique Martinet To: swupdate@googlegroups.com, sbabic@denx.de Cc: Dominique Martinet Subject: [swupdate] [PATCH 5/6] install_from_file: initialize and take mymutex earlier Date: Sat, 23 Apr 2022 08:59:43 +0900 Message-Id: <20220422235944.2808227-5-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220422235944.2808227-1-dominique.martinet@atmark-techno.com> References: <20220422235944.2808227-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , if async_thread finishes really fast, it's possible it'd try to call end callback to signal us before we're waiting for it, leaving us hanging here. This completes the previous patch for swupdate -i Signed-off-by: Dominique Martinet Reviewed-by: Stefano babic --- (side-comment: shall we use that occasion to rename 'mymutex' ?) Note I didn't try to reproduce this bug, but I've seen it on other programs so I'm sure this is wrong. I actually did that change first so I didn't try the previous patch without this. (Thinking about it again, it's almost impossible to hit right now because the current async_thread sleeps 1s before exiting whatever happens, so we have 1s to get to that lock initialization/cond wait, but that doesn't make this correct) core/install_from_file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/install_from_file.c b/core/install_from_file.c index 2230a4f88f3b..66b66372c7cd 100644 --- a/core/install_from_file.c +++ b/core/install_from_file.c @@ -88,6 +88,8 @@ int install_from_file(const char *filename, bool check) if (check) req.dry_run = RUN_DRYRUN; + pthread_mutex_init(&mymutex, NULL); + pthread_mutex_lock(&mymutex); while (timeout_cnt > 0) { rc = swupdate_async_start(readimage, NULL, endupdate, &req, sizeof(req)); @@ -104,10 +106,8 @@ int install_from_file(const char *filename, bool check) return EXIT_FAILURE; } - pthread_mutex_init(&mymutex, NULL); /* Now block */ - pthread_mutex_lock(&mymutex); pthread_cond_wait(&cv_end, &mymutex); pthread_mutex_unlock(&mymutex);