Received: by 10.192.165.148 with SMTP id m20csp3811606imm; Mon, 7 May 2018 20:29:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpjC7scpyuBrVPOjBB4QDcAK5QcHG7qV+DcMOMmYqWqL7q32PI3Ps6YVuN8vuq2CEnD1KiO X-Received: by 2002:a63:9e12:: with SMTP id s18-v6mr21235290pgd.207.1525750148457; Mon, 07 May 2018 20:29:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525750148; cv=none; d=google.com; s=arc-20160816; b=Q6O90LpZxc1N7p1EtD2BaXHhtdHrGx7HayvR/Y1d+HGUofAt5W8yveKHqvBc3Inb+W xmup+G9HOj4FKhfXb9+sd+oCDzlTjs2xc9LAOvVN1GRowHDsks7cbQPwMiKjGWwPnQkA Mqqo6nJJyj5lMAmn4ExCI3FcsDY0vZlah0xOPnHre/xzcaBvfHBBRgFyaMsjLNblWfiK I17XoDZCLbRYpEESQ9OrZJT4BeLi349VPzskhRVReuSxMBKdBjIdRqHiYF268nL8QSJt IdyKrZePaLzP7WndGLq4aVRBD9rmGKxctKlvTYwwE6yCqCvIh/qz67Roszk+7065K6Nd xFQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=87syGXMTEOcA32A9ZA7fhNvVhzlKX5F/cTJTGegnu5Y=; b=toAR1wLMqLOc5m5F7P9hnekVdjakuXItBTYrIZ89As0vcIqN2SWg8NxqCCYFpZX59c /ClxPxmqJ9cfJJVo37qJZ3h6nJe5tiPLN3TTU8iIApaO+RUQEDg15I1JgBKRDqfGG+sT 5dbbXPC4jcY7s6vxyk70yy9OViOZh/YFsfyjXRCpq6BpO21Gh4HlSGgRI/h48y5imJCY XaSGFqsc5dZQnPSvYlzH6Ka+/18gOQaHWP4EoHNtWy/wOu29EGUO2Q16nMOZBOnZ+hX6 uj1pD+YW50yMWipvCihj1BKIAJwfho1xILyEBvSjzKhiLjZw+bDzWjF7yvt5OgylhNkV njrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XJJ3nZRZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p66-v6si19018918pga.180.2018.05.07.20.28.53; Mon, 07 May 2018 20:29:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XJJ3nZRZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754002AbeEHD2k (ORCPT + 99 others); Mon, 7 May 2018 23:28:40 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:44756 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753896AbeEHD2i (ORCPT ); Mon, 7 May 2018 23:28:38 -0400 Received: by mail-pg0-f66.google.com with SMTP id x145-v6so273885pgx.11; Mon, 07 May 2018 20:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=87syGXMTEOcA32A9ZA7fhNvVhzlKX5F/cTJTGegnu5Y=; b=XJJ3nZRZeV5KbbDoTgpbf7wEHA3Ac0JGAqlc975kwFPIN+2GHO/Nvs9lxI3/GKtCeQ mnbmKaXI+kWK5tZpj5T3+J9rE7ccQPdRR3Nqc3tT2jaNXJdyQt9R5u6yUP9PUYb6JDtC wke4nPEIqlFk2f3Ws0nmeXFII083XcIepRBk1aNSVth1jZdrCrWZQGmcSnYylXIK5c1L cShVevEJwAbxByY33Vx9yngbc9On0+KmFf9qdoTA6Arxzvm1BWT2S/mE7f85/0GIbu4h gM9yORqhUMDq5TtdtgTNgmJ7UQKE+90YzYMK0TAWeJTqGKcKAPEiJn2DkEDvUT8WvJJM Ycfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=87syGXMTEOcA32A9ZA7fhNvVhzlKX5F/cTJTGegnu5Y=; b=q8LphMFBMHPq0qj85fRByG+gvlnYnmSwkmzbD0Hr/KEGvwoLsIhZEkFOZxoUb/Btqf 6ztAuvlNbPCRFLLCQQhWUWob4Sv+uSQh50aodLYLrNm0X858Ay2LsVFK0Rv4yRC6pzz8 wrWSF58I2INgWUAGubNtKD0bHhP9ZDu6EhfxYC0PJLj3LDM6D53t0dcevnfJwaHzofks RUWpWdRtPLc7JsA1MYxO/8tl5nJ89pLs2f1laC2USAl/zmCYqaCq0/GJRCWWtMiNXk9f RykhujFLd5w/T2sIiVdNE+2R4+CZUIAeyFifZpFoCXCKOW766gvtixYPOt2Q5DvPjKY+ eD4A== X-Gm-Message-State: ALQs6tCs3HPRjaZ/bL5NqEjCUhjg/r7pq7F0hCsXnl4kb/49UoJkrG03 wFwOr6+CGwoBZvTi3VBGgYaqTQ== X-Received: by 2002:a65:5b4a:: with SMTP id y10-v6mr31646984pgr.243.1525750117345; Mon, 07 May 2018 20:28:37 -0700 (PDT) Received: from server.roeck-us.net (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by smtp.gmail.com with ESMTPSA id 65sm49761360pft.74.2018.05.07.20.28.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 20:28:36 -0700 (PDT) Subject: Re: [PATCH] watchdog: mena21_wdt: Fix a possible data race in a21_wdt_set_timeout To: Jia-Ju Bai , morbidrsa@gmail.com, wim@linux-watchdog.org Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org References: <20180508031825.12525-1-baijiaju1990@gmail.com> From: Guenter Roeck Message-ID: <64e08944-0578-ac4c-8dea-e1e704685e77@roeck-us.net> Date: Mon, 7 May 2018 20:28:34 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180508031825.12525-1-baijiaju1990@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/07/2018 08:18 PM, Jia-Ju Bai wrote: > The write operation to "wdt->timeout" is protected by > the lock on line 118, but the read operation to > this data on line 105 is not protected by the lock. > Thus, there may exist a data race for "wdt->timeout". > > To fix this data race, the read operation to "wdt->timeout" > should be also protected by the lock. > There is no race. There is already a mutex in the watchdog core which serializes calls to the various API functions. It would make more sense to drop drv->lock from the driver. Guenter > Signed-off-by: Jia-Ju Bai > --- > drivers/watchdog/mena21_wdt.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c > index 25d5d2b8cfbe..05ca69042829 100644 > --- a/drivers/watchdog/mena21_wdt.c > +++ b/drivers/watchdog/mena21_wdt.c > @@ -102,14 +102,15 @@ static int a21_wdt_set_timeout(struct watchdog_device *wdt, > return -EINVAL; > } > > + mutex_lock(&drv->lock); > + > if (timeout == 30 && wdt->timeout == 1) { > + mutex_unlock(&drv->lock); > dev_err(wdt->parent, > "Transition from fast to slow mode not allowed\n"); > return -EINVAL; > } > > - mutex_lock(&drv->lock); > - > if (timeout == 1) > gpio_set_value(drv->gpios[GPIO_WD_FAST], 1); > else >