From patchwork Fri Nov 22 06:54:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 3221541 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 591A19F461 for ; Fri, 22 Nov 2013 07:00:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ECBB720780 for ; Fri, 22 Nov 2013 07:00:44 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BD22C2076B for ; Fri, 22 Nov 2013 07:00:43 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VjkjE-0004YL-UO; Fri, 22 Nov 2013 07:00:37 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VjkjC-0007VH-GY; Fri, 22 Nov 2013 07:00:34 +0000 Received: from mail-ve0-f179.google.com ([209.85.128.179]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vjkj8-0007Ug-Hc for linux-arm-kernel@lists.infradead.org; Fri, 22 Nov 2013 07:00:31 +0000 Received: by mail-ve0-f179.google.com with SMTP id jw12so623050veb.10 for ; Thu, 21 Nov 2013 23:00:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=+K3EPrhzaiHCkQQNEn0Azac/l9I/0zNnN514WOp+fXA=; b=kjH/QRJXM7snN08skS8r/ii4lllVtN6qyeGOwc910AF9uitAAd1Yw46JLa+h1ddhhe 0F38bPxWuweUji/JU+bPN3G4neDUITsszOllVVFGQlxLy7cUeqaT7HdETaI7xkJFZATb XBrobDXt63oWASzAWdgaK5JtzFHG0k4xDa5gOOpW/LFZ/cbhjKfP3LM50bsrI1YZ5/1E ws9weIr6hDYEJvtAZTvbPIbYx8nCjrQQ7cgVen0TI6pzdEl5WhCG8iQ8evkL+Q4b6LyA aFRTD2hYiyn3aarp8qWgHJVTfwwJJtpYMLNqNxaEuq4syrnQlCfmSr/nZY1t5uZBppI5 yukg== X-Gm-Message-State: ALoCoQnaAnc/V7nQuOJnNJVzRyXMf1El2qMwALC+fayinOw23NDO7Ac4mneuyVGUADe+zx3to8Yb MIME-Version: 1.0 X-Received: by 10.58.146.71 with SMTP id ta7mr6922443veb.23.1385103267086; Thu, 21 Nov 2013 22:54:27 -0800 (PST) Received: by 10.58.38.231 with HTTP; Thu, 21 Nov 2013 22:54:26 -0800 (PST) In-Reply-To: <528E4F55.9070204@wwwdotorg.org> References: <1384548866-13141-1-git-send-email-swarren@wwwdotorg.org> <1384548866-13141-12-git-send-email-swarren@wwwdotorg.org> <1384766276.14845.155.camel@smile> <528A5170.3090809@wwwdotorg.org> <1384862421.14845.222.camel@smile> <528B9CAE.3040600@wwwdotorg.org> <528BFDD0.3090503@wwwdotorg.org> <528CFE68.6060908@wwwdotorg.org> <528D0C06.9080006@wwwdotorg.org> <1384979000.2067.5.camel@dwillia2-mobl1.amr.corp.intel.com> <528D28A1.2050307@wwwdotorg.org> <528E4F55.9070204@wwwdotorg.org> Date: Thu, 21 Nov 2013 22:54:26 -0800 Message-ID: Subject: Re: [PATCH 11/31] dma: add channel request API that supports deferred probe From: Dan Williams To: Stephen Warren X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131122_020030_616516_A778F359 X-CRM114-Status: GOOD ( 21.82 ) X-Spam-Score: -2.6 (--) Cc: "treding@nvidia.com" , Stephen Warren , "Koul, Vinod" , "pdeschrijver@nvidia.com" , "linux-tegra@vger.kernel.org" , "dmaengine@vger.kernel.org" , Andy Shevchenko , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Nov 21, 2013 at 10:22 AM, Stephen Warren wrote: > On 11/20/2013 08:22 PM, Dan Williams wrote: >> On Wed, Nov 20, 2013 at 1:24 PM, Stephen Warren wrote: >>> On 11/20/2013 01:23 PM, Williams, Dan J wrote: >>> ... >>>> Why do the drivers that call dma_request_channel need to convert it to >>>> an ERR value? i.e. what's problematic about the below (not compile >>>> tested)? >>> ... >>>> diff --git a/arch/arm/plat-samsung/dma-ops.c b/arch/arm/plat-samsung/dma-ops.c >>> ... >>>> @@ -22,16 +22,20 @@ static unsigned samsung_dmadev_request(enum dma_ch dma_ch, >>>> struct samsung_dma_req *param, >>>> struct device *dev, char *ch_name) >>> ... >>>> + if (dev->of_node) { >>>> + chan = dma_request_slave_channel(dev, ch_name); >>>> + return IS_ERR(chan) ? (unsigned) NULL : (unsigned) chan; >>>> + } else { >>>> return (unsigned)dma_request_channel(mask, pl330_filter, >>>> (void *)dma_ch); >>>> + } >>> >>> The argument is that if a function returns errors encoded as an ERR >>> pointer, then callers must assume that any non-IS_ERR value that the >>> function returns is valid. NULL is one of those values. As such, callers >>> can no longer check the value against NULL, but must use IS_ERR(). >>> Converting any IS_ERR() returns to NULL theoretically is the act of >>> converting one valid return value to some other completely random return >>> value. >> >> You describe how IS_ERR() works, but you didn't address the patch. >> There's nothing random about the changes to samsung_dmadev_request(). >> It still returns NULL or a valid channel just as before. > > I was addressing the patch. I guess I should have explained as follows. > > First, the following code is technically buggy: No, it's not, but I think we have different implementations in mind. > > + chan = dma_request_slave_channel(dev, ch_name); > + return IS_ERR(chan) ? (unsigned) NULL : (unsigned) chan; > > ... since it assumes that dma_request_slave_channel() never returns NULL > as a valid non-error value. This is specifically prohibited by the fact > that dma_request_slave_channel() returns either an ERR value or a valid > value; in that case, NULL is not an ERR value, and hence must be > considered valid. Let's stop there and be clear we are talking about the same proposal. The proposal is dma_request_slave_channel only returns errors or valid pointers, never NULL. In the above the assumption is that of_dma_request_slave_channel() is modified to guarantee it only returns ERR_PTRs or valid pointers never NULL. acpi_dma_request_slave_chan_by_name() can continue returning NULL and dma_request_slave_channel will translate it to an ERR_PTR, or you can convert it as you do in your patch. Not much value in converting acpi_dma_request_slave_chan_by_name as it does not return EPROBE_DEFER and nothing currently cares about the other error values. diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 9162ac80c18f..64c163664b9d 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -593,15 +593,20 @@ EXPORT_SYMBOL_GPL(__dma_request_channel); */ struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name) { + struct dma_chan *chan = ERR_PTR(-ENODEV); + /* If device-tree is present get slave info from here */ if (dev->of_node) return of_dma_request_slave_channel(dev->of_node, name); /* If device was enumerated by ACPI get slave info from here */ - if (ACPI_HANDLE(dev)) - return acpi_dma_request_slave_chan_by_name(dev, name); + if (ACPI_HANDLE(dev)) { + chan = acpi_dma_request_slave_chan_by_name(dev, name); + if (!chan) + chan = ERR_PTR(-ENODEV); + } - return NULL; + return chan; }