Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp17711img; Thu, 21 Mar 2019 13:03:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqy011Xhahn1kfEeHcN9CLlo/9wrVcMsdR/FsEq0s7ksZipj2aZYcQ/BkgD1D25VVpsashxk X-Received: by 2002:a63:5a1d:: with SMTP id o29mr60181pgb.320.1553198598323; Thu, 21 Mar 2019 13:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553198598; cv=none; d=google.com; s=arc-20160816; b=FqmZCmiejFycn6YAA9/n1SJLZ8wPZMk/75b35oUQDAiwxKcJb5Brj/sYIuhl0KHPrl o3sC4csfm6Ae+Y324/tiBtYXRXa3t2lryRc7yd/7cvu/KqhM77yslwKsVxdfXSwEERs+ 0zIdFW6OZFkz86+Qt9xKtKhLHshxcPV4eSi2XHWyb04NTPpnuhkqvwXzeqiiyKLodWgp 2ngQxz/OK6K4+HD9rEaVKt1kyVQvr7GaIPQA6EhFU8hDtbaEByT03flDX+CPO0XPzMHO 7L09emdF1MqJNrxLHHGDUbPzuggVO2GIDYxqLE5WZ+m8/EtIY8uIT0I2KnMP41SrSBOd Xu8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1onto69JfOi03nkyfcMMs0TGjQavCF+XTqLUFtGG5Zg=; b=0Din/VDV20ajmy0cUOW2j4UFV/z8Gxhx0+6PcfjZFekv2TJRQ+Dn4/pVl8zXwpHGf0 w9m+INbWTDoeyFwP4Badv+37YmHQkTyBkITzU3j6o414XxeLzGeUuEotOQf9sDtGFr+z lBqQqQHQCbKla3LzEmAHQNQ9NHUp9uCnM+qZ5+MeC9jhpPDigiyaVPO9dk6bG+hSL7VV TJgcKS4kXcn/PqRdWxr8TxeBy7gQbgmjwhy6gVDmz8KTVVr4nmZrQCchr5gUjMQdcwrc U82tDp0oCo9+/XaVZzh51cwPF+qPNp8/CgRUPuWPQ0lePEaY3/D8APqBACvCDOBzVCLF cW0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wxYc+sM2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s26si4096388pgk.380.2019.03.21.13.02.54; Thu, 21 Mar 2019 13:03:18 -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; dkim=pass header.i=@linaro.org header.s=google header.b=wxYc+sM2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728783AbfCUUB0 (ORCPT + 99 others); Thu, 21 Mar 2019 16:01:26 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40356 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727914AbfCUUBZ (ORCPT ); Thu, 21 Mar 2019 16:01:25 -0400 Received: by mail-wr1-f68.google.com with SMTP id t5so8010859wri.7 for ; Thu, 21 Mar 2019 13:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1onto69JfOi03nkyfcMMs0TGjQavCF+XTqLUFtGG5Zg=; b=wxYc+sM2zKEOSLsHZycdm+ChzhdUS7dW1AfoMJVV33nrTxyeNpN/rDK9+82rfIFKRH S7To3zC3qIitysREKDbd83c0icPeJh75I2uuxqYcZuC0OlOYnHGkQmTr0LKQ7/Og6CRq igGD4cpo09NCWLcpTQk7J0OYGMD7f8GRraAyw2KY9FibBPP2MVNboxEwtj6zCgdzZOOT SaNOpCCo62Y+ODJSwX4iI96UoZksyh4oHG6EFdLDGgk05IJcWNMi41VrUgKIW4diZaaj EkaMK2R5SjbtjwJmU6orq6tB42sON3SVM5MD0aju/jKKhO5wzb0pXVZ9h9WJ18sT3GLo 9ahg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1onto69JfOi03nkyfcMMs0TGjQavCF+XTqLUFtGG5Zg=; b=V+UzFmTdggHVjDlP9dtw9dRov2UoL6MpBDum56sihtlhhc6p5FUwOLIGN9L2GQ1MUh nfS5rWUTk/vKy36SNFlfjtRnI808U1YDv9PrGF9/HIs6mYCfyzEA+eL2wmtSBejTgB6v TTC0xkVgwrqpvR5g7xO1oFtygSJ5y32iLuwyVvpahCTuNaZls45hfR0uj1xHQgAUtb87 Px5wkterFOXy90w9XuYXo42DDR3bDrKQEIlDv07srqHrxWCuby9WA8Fq2dS3DtSOp4tz xKofE2ZjAd8x7Uu5M++JSndQlZgl0ev3EyRiyKFan2iWkm79P74yOb3TAf2Fydc3v9v4 ZeRw== X-Gm-Message-State: APjAAAV3AjoznfVrl/JFaib2kDRivCq8nqUW6R2wDkuZk9PFMaYVsYD8 sTzyceCpAG2f8K7DeFsMadXv3rP2M91O91YvQsrP7g== X-Received: by 2002:adf:ea0b:: with SMTP id q11mr2379965wrm.233.1553198483893; Thu, 21 Mar 2019 13:01:23 -0700 (PDT) MIME-Version: 1.0 References: <1551819273-640-1-git-send-email-john.stultz@linaro.org> <1551819273-640-3-git-send-email-john.stultz@linaro.org> <20190315090646.GC4470@infradead.org> In-Reply-To: <20190315090646.GC4470@infradead.org> From: John Stultz Date: Thu, 21 Mar 2019 13:01:12 -0700 Message-ID: Subject: Re: [RFC][PATCH 2/5 v2] dma-buf: heaps: Add heap helpers To: Christoph Hellwig Cc: lkml , Laura Abbott , Benjamin Gaignard , Greg KH , Sumit Semwal , Liam Mark , Brian Starkey , "Andrew F . Davis" , Chenbo Feng , Alistair Strachan , dri-devel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 15, 2019 at 2:06 AM Christoph Hellwig wrote: > > + if (buffer->kmap_cnt) { > > + buffer->kmap_cnt++; > > + return buffer->vaddr; > > + } > > + vaddr = dma_heap_map_kernel(buffer); > > + if (WARN_ONCE(!vaddr, > > + "heap->ops->map_kernel should return ERR_PTR on error")) > > + return ERR_PTR(-EINVAL); > > + if (IS_ERR(vaddr)) > > + return vaddr; > > + buffer->vaddr = vaddr; > > + buffer->kmap_cnt++; > > The cnt manioulation is odd. The normal way to make this readable > is to use a postfix op on the check, as that makes it clear to everyone, > e.g.: > > if (buffer->kmap_cnt++) > return buffer->vaddr; > .. Thanks again on the feedback, I have had some other distractions recently, so just getting around to these details again now. The trouble w/ the suggestion here, if we increment in the check, then if we trip on any of the other error paths, the cnt value will be wrong when we return (and doing the extra decrementing in the error paths feels as ugly as just doing the increment at the end of the success paths) > > + buffer->kmap_cnt--; > > + if (!buffer->kmap_cnt) { > > + vunmap(buffer->vaddr); > > + buffer->vaddr = NULL; > > + } > > Same here, just with an infix. > > > +static inline void INIT_HEAP_HELPER_BUFFER(struct heap_helper_buffer *buffer, > > + void (*free)(struct heap_helper_buffer *)) > > +{ > > + buffer->private_flags = 0; > > + buffer->priv_virt = NULL; > > + mutex_init(&buffer->lock); > > + buffer->kmap_cnt = 0; > > + buffer->vaddr = NULL; > > + buffer->sg_table = NULL; > > + INIT_LIST_HEAD(&buffer->attachments); > > + buffer->free = free; > > +} > > There is absolutely no reason to inlines this as far as I can tell. Yea, I think I was mimicing some of the helpers like INIT_LIST_HEAD() But sounds good. I can uninline it. > Also it would seem much simpler to simply let the caller assign the > free callback. Yea, its a bit ugly but I worry the caller might forget? Thanks again for the feedback! -john