From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 0096C8634F for ; Fri, 20 Dec 2024 07:46:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734680774; cv=none; b=tVSry5W1eDArCfpfyqOJmYArg+/I4QahbErddCu3CKzPoRpjBYDX9LAnhdxYdAK4Cpbk5m9IQlKDYv0h7li2uijeDIiHYHgJ4kxVfILhSKov7mh/6WT1g15rr8b06siTVKhY7mp7IMWdNldRMwGKRdNlL3ipZH/p3hmcUkscDLk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734680774; c=relaxed/simple; bh=cc9Z4vtC4BNMXHFh4FmjsIq/FKot5DMM/IP2qX3btUo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V1QxKN92c/3sXNj2HIWOYiH1+ikXFvW+zMUotC37eZEFngfaCQj5rQ7ji8kargsFS4QcPyVbdIW8HBMLtWDz0YX7xuTwg4lbozZVaty7zSHeX1uf2eXIIyK3fOUJGzj/eQIs71gKsLZcfzA5VX7BvmqFWnb1myvzZeLda/HusKs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tOXhw-0004Qw-1Z; Fri, 20 Dec 2024 08:46:00 +0100 Received: from pty.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::c5]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tOXhu-004L5Y-2b; Fri, 20 Dec 2024 08:45:59 +0100 Received: from ore by pty.whiteo.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1tOXhv-00ANip-1X; Fri, 20 Dec 2024 08:45:59 +0100 Date: Fri, 20 Dec 2024 08:45:59 +0100 From: Oleksij Rempel To: Carlos Song Cc: Ahmad Fatoum , Andi Shyti , Frank Li , "kernel@pengutronix.de" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "festevam@gmail.com" , "linux-i2c@vger.kernel.org" , "imx@lists.linux.dev" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , Clark Wang Subject: Re: [PATCH v5] i2c: imx: support DMA defer probing Message-ID: References: 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=utf-8 Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org On Fri, Dec 20, 2024 at 07:38:47AM +0000, Carlos Song wrote: > > > > -----Original Message----- > > From: Oleksij Rempel > > Sent: Friday, December 20, 2024 3:35 PM > > To: Ahmad Fatoum > > Cc: Carlos Song ; Andi Shyti ; > > Frank Li ; kernel@pengutronix.de; shawnguo@kernel.org; > > s.hauer@pengutronix.de; festevam@gmail.com; linux-i2c@vger.kernel.org; > > imx@lists.linux.dev; linux-arm-kernel@lists.infradead.org; > > linux-kernel@vger.kernel.org; Clark Wang > > Subject: [EXT] Re: [PATCH v5] i2c: imx: support DMA defer probing > > > > Caution: This is an external email. Please take care when clicking links or > > opening attachments. When in doubt, report the message using the 'Report this > > email' button > > > > > > On Fri, Dec 20, 2024 at 08:06:25AM +0100, Ahmad Fatoum wrote: > > > Hello Carlos, > > > > > > On 20.12.24 07:58, Carlos Song wrote: > > > > > > > > > > > >> -----Original Message----- > > > >> From: Oleksij Rempel > > > >> Sent: Friday, December 20, 2024 2:13 PM > > > >> To: Carlos Song > > > >> Cc: Andi Shyti ; Frank Li > > > >> ; kernel@pengutronix.de; shawnguo@kernel.org; > > > >> s.hauer@pengutronix.de; festevam@gmail.com; > > > >> linux-i2c@vger.kernel.org; imx@lists.linux.dev; > > > >> linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; > > > >> Clark Wang ; Ahmad Fatoum > > > >> > > > >> Subject: [EXT] Re: [PATCH v5] i2c: imx: support DMA defer probing > > > >> > > > >> Caution: This is an external email. Please take care when clicking > > > >> links or opening attachments. When in doubt, report the message > > > >> using the 'Report this email' button > > > >> > > > >> > > > >> On Fri, Dec 20, 2024 at 05:59:38AM +0000, Carlos Song wrote: > > > >>>>> So we make this logic. Anyway we let the I2C controller > > > >>>>> registered whether > > > >>>> DMA is available or not(except defer probe). > > > >>>>> Ignoring ENODEV and EPROBE_DEFER makes it looks like nothing > > > >>>>> happened if > > > >>>> DMA is defer probed or not enabled(This is an expected). > > > >>>>> However we still need i2c DMA status is known when meet an > > > >>>>> unexpected > > > >>>> error, so we use dev_err_probe() to print error. > > > >>>> > > > >>>> Why dev_err_probe() instead of dev_err()? > > > >>>> > > > >>> Hi, > > > >>> In patch V2 discussion, Marc suggested just return > > > >>> dev_err_probe(), but I don't accept it so I choose to use > > > >>> dev_err_probe() to print error in V3.[1] > > > >> In this case, the two APIs have the same function, do you mean > > > >> dev_err() is more suitable? > > > >> > > > >> Yes, dev_err_probe() should be used in combination with return. For > > > >> example: > > > >> return dev_err_probe(...); > > > >> > > > >> It will pass the return value on exit of the function and > > > >> optionally print of the error message if it is not EPROBE_DEFER. > > > >> Practically it replace commonly used coding pattern: > > > >> if (ret == -EPROBE_DEFER) { > > > >> return ret; > > > >> } else if (ret) { > > > >> dev_err(..); > > > >> return ret; > > > >> } > > > >> > > > > Hi, > > > > > > > > Get your good point. I will change my code in V6: > > > > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > > + if (ret) { > > > > + if (ret == -EPROBE_DEFER) > > > > + goto clk_notifier_unregister; > > > > + else if (ret == -ENODEV) > > > > + dev_dbg(&pdev->dev, "Only use PIO > > mode\n"); > > > > + else > > > > + dev_err(&pdev->dev, "Failed to setup DMA, > > only use PIO mode\n"); > > > > + } > > > > > > > > I think this is what you want to see, right? > > > > > > This loses the information why the error happens (ret). Using > > > dev_err_probe even if no probe deferral is expected in that branch is > > > perfectly fine and the kernel-doc even points it out: > > > > > > Using this helper in your probe function is totally fine even if @err > > > is known to never be -EPROBE_DEFER. > > > > Thank you for the feedback. While I recognize the benefits of > > dev_err_probe() for compact and standardized error handling, using it without > > returning its result raises a red flag. > > > > The function's primary purpose is to combine error logging with returning the > > error code. If the return value is not used, it can create confusion and suggests > > potential oversight or unintended behavior. This misuse might mislead readers > > into thinking that the function always returns at that point, which is not the case > > here. > > > > In this scenario, using dev_err() directly is more explicit and avoids any ambiguity > > about the control flow or error handling intent. It keeps the code clear and > > aligned with its actual behavior. > > > > how about this? > > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > + if (ret) { > + if (ret == -EPROBE_DEFER) > + goto clk_notifier_unregister; > + else if (ret == -ENODEV) > + dev_dbg(&pdev->dev, "Only use PIO mode\n"); > + else > + dev_err(&pdev->dev, "Failed to setup DMA (%d), only use PIO mode\n", ret); > + } Please use human readable version of error value. In this case it will be: dev_err(&pdev->dev, "Failed to setup DMA (%pe), only use PIO mode\n", ERR_PTR(ret)); -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |