From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7291C4320A for ; Wed, 18 Aug 2021 12:46:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B2CFD61051 for ; Wed, 18 Aug 2021 12:46:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B2CFD61051 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C61C16E58E; Wed, 18 Aug 2021 12:46:46 +0000 (UTC) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by gabe.freedesktop.org (Postfix) with ESMTPS id D40B16E58A for ; Wed, 18 Aug 2021 12:46:44 +0000 (UTC) Received: by mail-wr1-x42f.google.com with SMTP id v4so3278555wro.12 for ; Wed, 18 Aug 2021 05:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=uP7fJxLQ5TTQ8aYHYwLJ/kNb8CkLiwmQWgbmcKMOm0w=; b=PS2hT9t/9lt08j1dPeij1H4maeOQEorQjjXGvVlj3rdRK5EGB3LBdL6ZFc5ihgsxu6 Raz3EniFUixp+J6NugUiY1vx8r7+9nC42cxjcI6WOR8VaONMTiKSM8toXdb/UC7G9576 ozvIPU2VygZBZ9UvUWtEYcANJ4iW6Vtt9Cpmc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=uP7fJxLQ5TTQ8aYHYwLJ/kNb8CkLiwmQWgbmcKMOm0w=; b=FD0Y/hsXZpMzU1pGq9somZssWkL2lvPof7dpXexXIQ2DXddgFKrErAueTWN/nN2owj 5bFn54uiahMig2vjGUlsE8oAmGt8RbjieHNQrw0ijnOJBbUZ/p4yMGvkn94rKOwqjX35 6RpQpL6/GBQ5IjCQ0it86gGV5bt2M8Tv3sNnK2l/sG3EqEXaQcQK+bctbJrA7usgpSPx T1w7wLWAvmzRe9qVZaQWYnAZNl7dtMCw2vNm0T9eideTYP2b9SFwaxCVAeCzdDZPDjZn dfyOHPhB39/BPJVTGzZjstwoB0wam/3MRdkwWIoG27MBAkv3S9Iwg8HRQKESzU5AiTKz bjmQ== X-Gm-Message-State: AOAM531dlTG4UEdzj8WXxyhS0nStECOHwl0ak/kHkjegYOx/uzDlZfhz DdXtrSt9tKGZGjmw55rGYdw+qg== X-Google-Smtp-Source: ABdhPJy9q41WJDBnQ045sdEUQOBByE6IbQCS+2X6AUgaQtPFfyt/n6ZzI0Dt7LogN6spZ356e/F0gg== X-Received: by 2002:adf:e38a:: with SMTP id e10mr10315579wrm.213.1629290802572; Wed, 18 Aug 2021 05:46:42 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id o7sm4916803wmc.46.2021.08.18.05.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 05:46:42 -0700 (PDT) Date: Wed, 18 Aug 2021 14:46:40 +0200 From: Daniel Vetter To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: "Sa, Nuno" , "linaro-mm-sig@lists.linaro.org" , "dri-devel@lists.freedesktop.org" , "linux-media@vger.kernel.org" , Rob Clark Subject: Re: [Linaro-mm-sig] [PATCH] dma-buf: return -EINVAL if dmabuf object is NULL Message-ID: References: <20210818115810.274084-1-nuno.sa@analog.com> <9a63b45f-6fec-6269-ae16-8604b08514de@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Operating-System: Linux phenom 5.10.0-7-amd64 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Wed, Aug 18, 2021 at 02:31:34PM +0200, Christian König wrote: > Am 18.08.21 um 14:17 schrieb Sa, Nuno: > > > From: Christian König > > > Sent: Wednesday, August 18, 2021 2:10 PM > > > To: Sa, Nuno ; linaro-mm-sig@lists.linaro.org; > > > dri-devel@lists.freedesktop.org; linux-media@vger.kernel.org > > > Cc: Rob Clark ; Sumit Semwal > > > > > > Subject: Re: [PATCH] dma-buf: return -EINVAL if dmabuf object is > > > NULL > > > > > > [External] > > > > > > To be honest I think the if(WARN_ON(!dmabuf)) return -EINVAL > > > handling > > > here is misleading in the first place. > > > > > > Returning -EINVAL on a hard coding error is not good practice and > > > should > > > probably be removed from the DMA-buf subsystem in general. > > Would you say to just return 0 then? I don't think that having the > > dereference is also good.. > > No, just run into the dereference. > > Passing NULL as the core object you are working on is a hard coding error > and not something we should bubble up as recoverable error. > > > I used -EINVAL to be coherent with the rest of the code. > > I rather suggest to remove the check elsewhere as well. It's a lot more complicated, and WARN_ON + bail out is rather well-established code-pattern. There's been plenty of discussions in the past that a BUG_ON is harmful since it makes debugging a major pain, e.g. https://lore.kernel.org/lkml/CA+55aFwyNTLuZgOWMTRuabWobF27ygskuxvFd-P0n-3UNT=0Og@mail.gmail.com/ There's also a checkpatch check for this. commit 9d3e3c705eb395528fd8f17208c87581b134da48 Author: Joe Perches Date: Wed Sep 9 15:37:27 2015 -0700 checkpatch: add warning on BUG/BUG_ON use Anyone who is paranoid about security crashes their machine on any WARNING anyway (like syzkaller does). My rule of thumb is that if the WARN_ON + bail-out code is just an if (WARN_ON()) return; then it's fine, if it's more then BUG_ON is the better choice perhaps. I think the worst choice is just removing all these checks, because a few code reorgs later you might not Oops immediately afterwards anymore, and then we'll merge potentially very busted new code. Which is no good. -Daniel > > Christian. > > > > > - Nuno Sá > > > > > Christian. > > > > > > Am 18.08.21 um 13:58 schrieb Nuno Sá: > > > > On top of warning about a NULL object, we also want to return with a > > > > proper error code (as done in 'dma_buf_begin_cpu_access()'). > > > Otherwise, > > > > we will get a NULL pointer dereference. > > > > > > > > Fixes: fc13020e086b ("dma-buf: add support for kernel cpu access") > > > > Signed-off-by: Nuno Sá > > > > --- > > > > drivers/dma-buf/dma-buf.c | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma- > > > buf.c > > > > index 63d32261b63f..8ec7876dd523 100644 > > > > --- a/drivers/dma-buf/dma-buf.c > > > > +++ b/drivers/dma-buf/dma-buf.c > > > > @@ -1231,7 +1231,8 @@ int dma_buf_end_cpu_access(struct > > > dma_buf *dmabuf, > > > > { > > > > int ret = 0; > > > > > > > > - WARN_ON(!dmabuf); > > > > + if (WARN_ON(!dmabuf)) > > > > + return -EINVAL; > > > > > > > > might_lock(&dmabuf->resv->lock.base); > > > > > > _______________________________________________ > Linaro-mm-sig mailing list > Linaro-mm-sig@lists.linaro.org > https://lists.linaro.org/mailman/listinfo/linaro-mm-sig -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch