Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp621916ybg; Tue, 28 Jul 2020 14:33:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWiF5Y4uuTytLUNSP8S3eAyqPVsZZfk5/QhND/+g8ZfrDFKsx2OTg6QuQ0CcwFYKXuccdQ X-Received: by 2002:a17:906:2b9b:: with SMTP id m27mr27527721ejg.19.1595972013226; Tue, 28 Jul 2020 14:33:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595972013; cv=none; d=google.com; s=arc-20160816; b=vPNuzvaXXRgUX0pMDFN6Ltiy4pkKpYKTd37OugKXIAAQYTh+Y4FRUKXxSPigONeYpy Dh9fpTWW4gXmpMJbnAKcWAMHdeSyYIPYJt3Gb1pflMt3SwMHauaVJsABguUpD5Z5y0SN SV6WO7wXYUX9fVlWXvMXL2/0Hb+QKIHlHhcdm3ujwyqw4KyYrCkSNhDcQ0uFbOHLwK2P zaJErzSydPadVNJ3CJpS2q5PCSBZOjq3PapvADCzWIgysoCixWBbtG/evJkJczTmVezo jxNhyCeW+gvZbhvuL32kvPfoLUrcg26x/cqpY/ynDXznCDzieAxN9ZVhfi3YPozRL21y Y10Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:date:to:cc:from :subject:references:in-reply-to:content-transfer-encoding :mime-version:dkim-signature; bh=nog6I1ImyNyq0+O1gfRhInkU2I7Jgi2bEICANP1hoBw=; b=JZgL/rEdzyT1Qm6bXFn+Wi8/e86vJXO1aYGxTr+8PAix6Y0nvjuDotxOxEslIw+clv ctnCAtwIsvuvYmbCCuIGqo4yFixPBbZuSpyc9VLIHsz3QC6D9ER/yboLJIfh9Zw38xKw 3NmRsc5QeUFkr+WMhJgXf7glX0a1zOnCu+m5vEJBSxJp/Akg5e5eE92xavT8TtZmgiKE 6yU/noG38r5ERESbZiegiMa4fnYGAmPeuycJUgqMLLaXYzp2CaH004M94dXfOLMVA6Ep rIP2l+AiWznQ/2fpxdWSF70KUm2vICped0ivG+eV6Me9k9Azee2puJ8pHA/iGKP3ki6h /StA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YK8aGH7h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce2si8641007edb.531.2020.07.28.14.33.10; Tue, 28 Jul 2020 14:33:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YK8aGH7h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729468AbgG1Vcb (ORCPT + 99 others); Tue, 28 Jul 2020 17:32:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729243AbgG1Vca (ORCPT ); Tue, 28 Jul 2020 17:32:30 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97F15C061794 for ; Tue, 28 Jul 2020 14:32:30 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id r4so83289pls.2 for ; Tue, 28 Jul 2020 14:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:content-transfer-encoding:in-reply-to:references :subject:from:cc:to:date:message-id:user-agent; bh=nog6I1ImyNyq0+O1gfRhInkU2I7Jgi2bEICANP1hoBw=; b=YK8aGH7hGj9Nh6bAPQGpVfyPuUN02hUZ+fVn6ryvf2tirGFUVzuzD4fUiRq8a4QYS+ grQHh7nvHbbXR/0d9nx9zOzqiWJKYbBXC6HV8bcyIELt2xk9opR02IU5ztm7C2XDaS7G mixfOgJxHyYaYryaQrM1zPmxoMl6q4/pB86Gs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding :in-reply-to:references:subject:from:cc:to:date:message-id :user-agent; bh=nog6I1ImyNyq0+O1gfRhInkU2I7Jgi2bEICANP1hoBw=; b=Pxi1BJHkBfmg/EP4ncpVMobX/9leuJy2ajbD3keWZThy9U88K8iDOdi9QU5mFT9p6L ZZTehaPphy+avmm2lmO+Q7f8/7inU2O5O9EXW+UjmfCUh2SZVHNqae8embDc6d2Gk69Z f3mLso/yBepT5PoyYiQmW7YgNge3Ad+j2puSzklbqEtw8dmh0BrRkvpD4HwxFH8PfQ52 85R9cpJ3DUBxqvwfA2pOXPHemgBkMRWnTOp0dzWJHAnNLdxAhMWiP1DQFzP1M8pzczP7 QAp8cW3vHAQbsSEOTLKH+qqNtxd8RtKm6/VATR5cY7oE8t3ocEJG2TJpRCiq4RPaWx1r YewQ== X-Gm-Message-State: AOAM530SfgTuG+K9WnUQevO7gykYy1PchRPVXzDFXZ/n5L74gRQnNTnO NCcncjEXGPByEU2sQeYXvFqwiA== X-Received: by 2002:a17:902:8685:: with SMTP id g5mr11281085plo.201.1595971950196; Tue, 28 Jul 2020 14:32:30 -0700 (PDT) Received: from chromium.org ([2620:15c:202:1:3e52:82ff:fe6c:83ab]) by smtp.gmail.com with ESMTPSA id f8sm18693pfk.107.2020.07.28.14.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2020 14:32:29 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: References: <20200724183954.1.I2e29ae25368ba8a72a9e44121cfbc36ead8ecc6b@changeid> <20200728151258.1222876-1-campello@chromium.org> <20200728091057.10.Ibe84fae61cd914c116e6d59ffeb644f1cbecd601@changeid> <159596523705.1360974.7169089810545711557@swboyd.mtv.corp.google.com> Subject: Re: [PATCH 10/15] iio: sx9310: Simplify error return handling From: Stephen Boyd Cc: LKML , LKML , Jonathan Cameron , Douglas Anderson , Enrico Granata , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio To: Daniel Campello Date: Tue, 28 Jul 2020 14:32:28 -0700 Message-ID: <159597194837.1360974.9212489704079396891@swboyd.mtv.corp.google.com> User-Agent: alot/0.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Daniel Campello (2020-07-28 14:23:29) > On Tue, Jul 28, 2020 at 1:40 PM Stephen Boyd wrote: > > > > Quoting Daniel Campello (2020-07-28 08:12:53) > > > @@ -368,13 +368,13 @@ static int sx9310_wait_for_sample(struct sx9310= _data *data) > > > static int sx9310_read_proximity(struct sx9310_data *data, > > > const struct iio_chan_spec *chan, in= t *val) > > > { > > > - int ret =3D 0; > > > + int ret; > > > __be16 rawval; > > > > > > mutex_lock(&data->mutex); > > > > > > ret =3D sx9310_get_read_channel(data, chan->channel); > > > - if (ret < 0) > > > + if (ret) > > > goto out; > > > > > > if (data->client->irq) { > > > @@ -394,11 +394,11 @@ static int sx9310_read_proximity(struct sx9310_= data *data, > > > > > > mutex_lock(&data->mutex); > > > > > > - if (ret < 0) > > > + if (ret) > > > goto out_disable_irq; > > > > Why is this condition checked after grabbing the mutex? Shouldn't it be > > checked before grabbing the mutex? Or is that supposed to be a > > mutex_unlock()? > We acquire the lock before jumping to out_disable_irq which is before > a mutex_unlock() Does this function need to hold the mutex lock around get/put_read_channel? It drops the lock while waiting and then regrabs it which seems to imply that another reader could come in and try to get the channel again during the wait. So put another way, it may be simpler to shorten the lock area and then bail out of this function to a place where the lock isn't held already on the return path.