Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3642721pxy; Mon, 26 Apr 2021 06:35:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxX+KO26dpfgm0Dko9DsAutySr+hQu06538En81nCfW0h7Nkq2ocFydCM+Hzx4VKQ3sfdC6 X-Received: by 2002:a17:90b:3887:: with SMTP id mu7mr21462039pjb.236.1619444129042; Mon, 26 Apr 2021 06:35:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619444129; cv=none; d=google.com; s=arc-20160816; b=UUIwHq9BtbYhKzpBhXynwzIvbSkwLQHpyUe9XbyrAz5ZBK/PisirhT9NHquG6C6jsZ 0U9lLHOlCzkHi8DkDhLYDuGXVayy+z+MmuZOT1KEnBSbKWm8Z8toikgqZYTNLLU+q3TR bhnqfEkzEWqRI53Wc9SQhEzRCUgIUAHgbAUf3OhQRAu/rIOWHCWDyDoqVEeEBu9ll4K1 memGYqMykX/K8QXhSKjsaxsYynlsI14lnWmCdTCFTEjO12OBVrO/U79yBQgPxjKQowQW Hr3BZ3fjxmC13UZt3f+DuIo8Rfu2gkExW3rYf88LtqVpsF4pz4gvs0BJZvMMLYUKNvHy S8Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=zavK4gQDJdW2wqw0EctnHA+BcQLgZX6MbrJsiaYgjwo=; b=QdZX6MttvbSm3snKWtSHnHfQDmxXZ2y3un7i7XlQHgjfwLKl9Z6QGhEtt5TMKrIlTf BhZd9+9HrCnDKx1Nu0345wuEOicw1dW4qX9fXLGxaO4H5r65jfVOUQPv2R2qFhe3iqGK EZotE5shzRCx5du8kU0X6wRrXhnfsV07skeFGcc3i0Pn/fAMHHc858U/O/bmv4PqzAc+ 4qmwHTM6BgXi77qBSiWL8XOssMCp58PDMQ9iknE1uuH2nKBSY6J/fHyKfKW9/h8tUHhl 11Pvz3zh7LOMIRxXCdq5tiLOlajPhaIBkwXUGrUgrdrZsQVIYRvLcZzTiUWYoOL8jrOP 53Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rrJxWff9; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e184si18787999pfe.58.2021.04.26.06.35.16; Mon, 26 Apr 2021 06:35:29 -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=@kernel.org header.s=k20201202 header.b=rrJxWff9; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233560AbhDZNd7 (ORCPT + 99 others); Mon, 26 Apr 2021 09:33:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:57024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230250AbhDZNd7 (ORCPT ); Mon, 26 Apr 2021 09:33:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C97B861157; Mon, 26 Apr 2021 13:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619443997; bh=KQQLpT4AI0vALszGg4C/76UWqxG1p2jCwpuYs8Uth+c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=rrJxWff9viv2SpQ1stnDkHN0QiY4YIYVZmmPqOfR8pTgUYiwKOM7mqhqKM3c6ZzdV gwnwpAIAsIMGl3N5kiMluQI6zzrWn0vbLkEda7V6MFo74kNiJZ+Mlaq9bWnAxovjig fybT/I85zYf/Z9Q8CuDdkZPuFAACPXVyYEnR+0QPDrQTcUhzDNVXjatCJoGvzmhHQw t6at5QwqjNwzJLqZ18dg1L7IcuujCdx3+tUBVMNyhyeEtydVNdS0Hp2Y/3OA6RGKo9 3d5VnrHcoai6bVG3lcr8K46Q0cjjoqomqn6vqKnAe/Fy0oeoEdRSe7W9soiV4CHtUM RzzoTfaV0BAfw== Date: Mon, 26 Apr 2021 15:33:11 +0200 From: Mauro Carvalho Chehab To: Geert Uytterhoeven Cc: Linuxarm , mauro.chehab@huawei.com, Niklas =?UTF-8?B?U8O2ZGVybHVuZA==?= , Mauro Carvalho Chehab , Linux Kernel Mailing List , Linux Media Mailing List , Linux-Renesas Subject: Re: [PATCH 69/78] media: rcar-vin: use pm_runtime_resume_and_get() Message-ID: <20210426153311.150f5b4f@coco.lan> In-Reply-To: References: X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sat, 24 Apr 2021 11:12:31 +0200 Geert Uytterhoeven escreveu: > Hi Mauro, > > On Sat, Apr 24, 2021 at 8:46 AM Mauro Carvalho Chehab > wrote: > > Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") > > added pm_runtime_resume_and_get() in order to automatically handle > > dev->power.usage_count decrement on errors. > > > > Use the new API, in order to cleanup the error check logic. > > > > Signed-off-by: Mauro Carvalho Chehab > > Thanks for your patch! > > > --- a/drivers/media/platform/rcar-vin/rcar-csi2.c > > +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c > > @@ -408,7 +408,7 @@ static void rcsi2_enter_standby(struct rcar_csi2 *priv) > > > > static void rcsi2_exit_standby(struct rcar_csi2 *priv) > > { > > - pm_runtime_get_sync(priv->dev); > > + pm_runtime_resume_and_get(priv->dev); > > I believe this part is incorrect: on failure[*], the refcount will now > be decremented, and in a subsequent call to rcsi2_enter_standby(), the > refcount will be decremented again due to the call to pm_runtime_put(). I see your point. > [*] On e.g. R-Car SoCs, this can never fail. This is the reason why > many R-Car (and SuperH) drivers never check the result of > pm_runtime_get_sync(). So the refcount "imbalances" were actually > introduced by the various "clean up" patches to add return value > checking, which now need another round of fixing... It sounds dangerous to assume that. I'm not a PM expert, but, at least looking at drivers/base/power/runtime.c, there are two situations where the core itself will return an error, even if the PM callback never return errors[1], and more could be added in the future: if (dev->power.runtime_error) retval = -EINVAL; else if (dev->power.disable_depth > 0) retval = -EACCES; [1] see rpm_resume() function IMO, the right thing here would be to check it at resume time, and to handle it properly. > > > reset_control_deassert(priv->rstc); > > } > > > --- a/drivers/media/platform/rcar-vin/rcar-dma.c > > +++ b/drivers/media/platform/rcar-vin/rcar-dma.c > > @@ -1458,11 +1458,9 @@ int rvin_set_channel_routing(struct rvin_dev *vin, u8 chsel) > > u32 vnmc; > > int ret; > > > > - ret = pm_runtime_get_sync(vin->dev); > > - if (ret < 0) { > > - pm_runtime_put_noidle(vin->dev); > > + ret = pm_runtime_resume_and_get(vin->dev); > > + if (ret < 0) > > return ret; > > - } > > This change (and the change below) is correct, as the logic before/after > is equivalent. > > Gr{oetje,eeting}s, > > Geert > Thanks, Mauro