Received: by 10.213.65.68 with SMTP id h4csp810205imn; Sun, 18 Mar 2018 03:18:01 -0700 (PDT) X-Google-Smtp-Source: AG47ELsLG0fC3CMiUDlIiD4PSnC9RgGX5GrPSSYYzuzeIS1BsDrTDrwYC9pM2opHdOzDyorYLzNU X-Received: by 10.99.0.2 with SMTP id 2mr1850308pga.395.1521368281785; Sun, 18 Mar 2018 03:18:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521368281; cv=none; d=google.com; s=arc-20160816; b=m3mqNK2NjccNab/vYI8Iv/bqGSRnfWL8QzVhBjkzPbaa6yDpP+elR+xz3P5jbRz3g/ asTK+tD5fApl+mX4XIiGx8tcobHlICWRJvl/cDduMbWJ9WINPFfDDRGdPzJ+VYC2RoqA DESNZAVXGmgN4MJh6mVPwdMXvj61RdhlBeXt7JTuTN0TzcCvJM6eQUqJrFxc1gGm89j+ tvtFSVtPdRK97eE/Ymu/MJWUtteUATENiiCpEOWICrscFmk6oEUKeD5o9+O8mPTzPcim ufuCQpvQ/i5AKKjfNAvjv5QPKrQu7bIdqdw15ordwAXmblRMG6a6JM36sMyy6QbK7UNj 6F2g== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dmarc-filter:arc-authentication-results; bh=/F3nMGTR/iCuIg/nzCELhYlSrQiWC9s2W18VZ+kAOts=; b=uKd1PKcdXSb5pJz5yzd4UaW0dPaAHnMgj8+LQV6zUqJUR4fULX5a91vjMQErqkWgeF 8kacZk7zeqgqmBRMG1pHUhYLbeLjMXpZUE21CTpnI/y6YCSzQqcjc6thwFHtVw0jUqOI 1AegY4IJQGHM/DVCFgI4vRuNZHMCRuEGVjcODN8wIbFTNO/lE0dIy8garxB6p+sdxToZ F2nK/JOgApgra+6614fmWEWzFfjbYicyqHzeDND5IjTR4+vPzNqbB0HiCeKhKrQYdC5A EnyB/iXD3vFpWoUg0F7VXnafN41nbIQ+5ibKhHZvgFRo8GXALbpRWvGOhkjCjPiU4yov rhmA== ARC-Authentication-Results: i=1; mx.google.com; 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 u6-v6si9913920pls.424.2018.03.18.03.17.47; Sun, 18 Mar 2018 03:18:01 -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; 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 S1754026AbeCRKPQ (ORCPT + 99 others); Sun, 18 Mar 2018 06:15:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:47320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751744AbeCRKPM (ORCPT ); Sun, 18 Mar 2018 06:15:12 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A868D20855; Sun, 18 Mar 2018 10:15:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A868D20855 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jic23@kernel.org Date: Sun, 18 Mar 2018 10:15:06 +0000 From: Jonathan Cameron To: SF Markus Elfring Cc: linux-iio@vger.kernel.org, Greg Kroah-Hartman , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Pravin Shedge , Quentin Schulz , LKML , kernel-janitors@vger.kernel.org Subject: Re: iio/gyro/bmg160_core: Improve unlocking of a mutex in five functions Message-ID: <20180318101506.460f3967@archlinux> In-Reply-To: <73f0a187-57d1-c877-ba9f-3b15f6a61640@users.sourceforge.net> References: <16623de4-351d-135b-f3ff-701a465c5d92@users.sourceforge.net> <20180317195422.037a8b57@archlinux> <73f0a187-57d1-c877-ba9f-3b15f6a61640@users.sourceforge.net> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 18 Mar 2018 09:19:47 +0100 SF Markus Elfring wrote: > Am 17.03.2018 um 20:54 schrieb Jonathan Cameron: > > On Wed, 14 Mar 2018 16:15:32 +0100 > > SF Markus Elfring wrote: > > > >> From: Markus Elfring > >> Date: Wed, 14 Mar 2018 16:06:49 +0100 > >> > >> * Add jump targets so that a call of the function "mutex_unlock" is stored > >> only once in these function implementations. > >> > >> * Replace 19 calls by goto statements. > >> > >> This issue was detected by using the Coccinelle software. > >> > >> Signed-off-by: Markus Elfring > > > > Hi Markus, > > > > Some of these are good and sensible changes > > Such feedback is nice. > > > > - others break the code. > > Which concrete places do you find questionable here? > > > >> - return ret; > >> + > >> + goto set_power_state; > >> default: > >> return -EINVAL; > > We exit with the mutex locked now and it should not be. > > I wonder about your source code interpretation here. > The mutex was (and is still only) locked within case branches, isn't it? > You are correct, this does however reflect the issue with the resulting lack of balance here. I saw the mutex was getting unlocked outside the local scope and so assumed that it was also take outside the local scope. That isn't true, so we have hurt readability. It might make sense to move the lock and unlock outside the switch statement but we certainly don't want to the the confusion that the lack of balance is causing here. I read it quickly and got the wrong idea which generally implies it is not as clear as we would like. Hence this change isn't going anywhere I'm afraid. Jonathan > > > > >> } > >> > >> return -EINVAL; > > Mutex is still locked here and the return is wrong. > > Should this statement get any more software development attention? > > Regards, > Markus