From patchwork Wed Aug 18 11:58:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nuno Sa X-Patchwork-Id: 12444157 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 6C8F4C4320A for ; Wed, 18 Aug 2021 11:55:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B5996108F for ; Wed, 18 Aug 2021 11:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233833AbhHRL40 (ORCPT ); Wed, 18 Aug 2021 07:56:26 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:34428 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231476AbhHRL4B (ORCPT ); Wed, 18 Aug 2021 07:56:01 -0400 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17I8Wt6N023819; Wed, 18 Aug 2021 07:55:18 -0400 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com with ESMTP id 3ag9e6fmbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 07:55:18 -0400 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 17IBtHEH020339 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Aug 2021 07:55:17 -0400 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.5; Wed, 18 Aug 2021 07:55:16 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.2.858.5 via Frontend Transport; Wed, 18 Aug 2021 07:55:16 -0400 Received: from nsa.ad.analog.com ([10.44.3.58]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 17IBtEUE031440; Wed, 18 Aug 2021 07:55:15 -0400 From: =?utf-8?q?Nuno_S=C3=A1?= To: , , CC: Rob Clark , =?utf-8?q?Christian_K=C3=B6nig?= , Sumit Semwal Subject: [PATCH] dma-buf: return -EINVAL if dmabuf object is NULL Date: Wed, 18 Aug 2021 13:58:10 +0200 Message-ID: <20210818115810.274084-1-nuno.sa@analog.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: VysZlt1syHx-snAeROfAhL42Qwl8f88W X-Proofpoint-ORIG-GUID: VysZlt1syHx-snAeROfAhL42Qwl8f88W X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-18_04,2021-08-17_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 priorityscore=1501 phishscore=0 impostorscore=0 bulkscore=0 mlxlogscore=978 adultscore=0 clxscore=1011 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108180075 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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);