From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC4383BF678 for ; Mon, 23 Mar 2026 16:35:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774283750; cv=none; b=NKwXASAy4ao0us4RQQ0nIcLAkEwp4zqxzTvHd06QMqHRJCMrn9UQD1kqOvUQPvXr/amPC5fDnKxcfxCiQw0c7MhrHm9gOC2k/YVQbAk0yGPL5QOG4JYTiEYRW84MNMlDKlJCUm82REgHX5yjoBW1Rt26hKjLXuqra3k2eOSsIQU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774283750; c=relaxed/simple; bh=X35BVJRRYPQD0gXzdQu/Fka4654j4zA8uiQxel1TpWw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JJzNMnrBXU7nWtc+1y1ltvQ70+b15fC9GO08T91HKH1r4TtyLV8RC4Mi3wCr4yVKt7tbmUWfhwN30SIyXACIyAfFe1BfDss4k3F+Cr9SoWNaA4XCqBlOFQA4a/ApCo2oGsYIjoSaRbdrXLz+d2g09xCOsNeN8TC9a0/OfgCplKk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ctUMtAwE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ctUMtAwE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90426C4CEF7; Mon, 23 Mar 2026 16:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774283750; bh=X35BVJRRYPQD0gXzdQu/Fka4654j4zA8uiQxel1TpWw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ctUMtAwEpIZvVC57pHTR04fbhVkQpnBS5S5zSYyPgRr058WNhgcDU0aSANpHvC8/2 zNtNA4Wnigx3P4kuGhrvSKSAVpBJQPRbB1Y/caFFTlF9utLA0DmeZpMuPZaWMn1xBs lUjqXfhgQbJkT+aCfKTzzrI4avktntVsgRow8q4tbWfRsm854waM9GYHLQUFU0mK+I OtyPSno3cgQOGXAUO7milcosaMzlvIUwE5f7dyzvA4qfy/LmtJSL1SBCLvZTmPLLS3 zk9PpvBkZc+wiiD1Z3oFYQnl2kvPbUWk6WCt7KAPERJNmlVi/ws5MWsZdQ0prTGmc7 0qGRTstYhqmEQ== Received: from johan by xi.lan with local (Exim 4.98.2) (envelope-from ) id 1w4iFo-00000003eDp-1vWC; Mon, 23 Mar 2026 17:35:48 +0100 Date: Mon, 23 Mar 2026 17:35:48 +0100 From: Johan Hovold To: Bartosz Golaszewski Cc: Srinivas Kandagatla , Bartosz Golaszewski , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/7] nvmem: simplify locking with guard() Message-ID: References: <20260223-nvmem-unbind-v2-0-0df33a933dca@oss.qualcomm.com> <20260223-nvmem-unbind-v2-4-0df33a933dca@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260223-nvmem-unbind-v2-4-0df33a933dca@oss.qualcomm.com> On Mon, Feb 23, 2026 at 11:57:05AM +0100, Bartosz Golaszewski wrote: > Use lock guards from cleanup.h to simplify locking. While at it: add the > missing mutex.h include. > @@ -1335,7 +1326,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) > > dev_id = dev_name(dev); > > - mutex_lock(&nvmem_lookup_mutex); > + guard(mutex)(&nvmem_mutex); > > list_for_each_entry(lookup, &nvmem_lookup_list, node) { > if ((strcmp(lookup->dev_id, dev_id) == 0) && > @@ -1343,11 +1334,9 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) > /* This is the right entry. */ > nvmem = __nvmem_device_get((void *)lookup->nvmem_name, > device_match_name); > - if (IS_ERR(nvmem)) { > + if (IS_ERR(nvmem)) > /* Provider may not be registered yet. */ > - cell = ERR_CAST(nvmem); > - break; > - } > + return ERR_CAST(nvmem); Please keep the brackets here for readability. > > cell_entry = nvmem_find_cell_entry_by_name(nvmem, > lookup->cell_name); > @@ -1363,7 +1352,6 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) > } > } > > - mutex_unlock(&nvmem_lookup_mutex); > return cell; > } > > @@ -1379,14 +1367,14 @@ nvmem_find_cell_entry_by_node(struct nvmem_device *nvmem, struct device_node *np > { > struct nvmem_cell_entry *iter, *cell = NULL; > > - mutex_lock(&nvmem_mutex); > + guard(mutex)(&nvmem_mutex); > + > list_for_each_entry(iter, &nvmem->cells, node) { > if (np == iter->np) { > cell = iter; > break; Shouldn't you return cell here now? > } > } > - mutex_unlock(&nvmem_mutex); > > return cell; > } And explicit NULL here (dropping the initialisation above)? Johan