From patchwork Tue Dec 15 22:05:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 344032 Delivered-To: patches@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4264537jai; Tue, 15 Dec 2020 14:05:27 -0800 (PST) X-Received: by 2002:a65:46c1:: with SMTP id n1mr30651970pgr.352.1608069927646; Tue, 15 Dec 2020 14:05:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608069927; cv=none; d=google.com; s=arc-20160816; b=BBahpxv0HyIvNXfhsy/Wpl12DIjLsqR/8lUIbzKSrnegYmz9QoARlPuSwN9ThrXYF0 nrQWc/sAJmShEjHRje0bNeRR05A7jMlhM62AyvPnUlyG5r+J5jOo6p0s23Szmd1bakyW AeTYSsMm/+lb3hfZd1Trh5cvFiEc0PzeKL+QRYKYJw/+do2v9iY6pwOQoAE8TD2cZc2s 80juK0eIAlR8wf/jf6JNvQVqgL4efYRQr4Ap35Dmj/uYGQtHOUyeI7UCkl77miy61NGt hl28sOJ/G/efYO5Gbw44K97oicKCJJQQsdYbCHFqD5A20mpoibytlCbhHF2XYgVVDzcf ZZMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Lf3OWtQTMarfh+qKkUU+h4c6HMQ0ofK4k7yhmGxtgVU=; b=e9zaDgVBRGgJdBpHTWZRtwDwcTRP8wpvEhNcSZgG5Q1o43QEQEYGZsOsAZt8VzJN5h nLCR4fGQAVxDfLjFRSFdjDi/EnyExbXMssLEZMSzVs7Zevn2yHL2dCMb+i0MCPLYQ0FW ruEffQMGWzTs3DBg33OaSSrhRptSgW9X+34U/o4RsQfpRXSxHavcsKE7MQRMPpbMNmYL EA4jBmNWItyvx3S+aZcEy2ymctUSf97U0ZluWEXcjfNZd22pp3jEmI3TzYXDGbpZ4YE7 KwzXNDSxvnLdDnFnJzgQAwIwnBlC/i5L1Yf0C2zOhbTt9wKS8SINLJWK7NUFhSRceovY JDjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p2xXtJcd; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id ms2sor82503pjb.21.2020.12.15.14.05.27 for (Google Transport Security); Tue, 15 Dec 2020 14:05:27 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p2xXtJcd; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lf3OWtQTMarfh+qKkUU+h4c6HMQ0ofK4k7yhmGxtgVU=; b=p2xXtJcd1aUEKVCpL/yh2zHAnUKUnnWwn3KT6xcvB1fmMbzbubeWxt0UWpAi+SHPkn Da0r6htfgSPk5GT5zFUAvAj9HKR9J/Xch76+SmRleDTarKBdtiMk2hQKTvM2ii03hq0R KNe5XFm+uN9nHsrs/7fQbU9hUvdU3DtCbiAiwhRgzj3BW22qCPr9aYCowWWF0o7lmeHN +uogQn6HoNI5bOkFqfS5YsBABPcVWeaO+cM8PfuMoVcYTBSXwRPkxCrLVmsuC5+LeIz8 GzNv13iEIXL2wrU8aqMcQJHQ4KKslM/A9tB8ab472EDm6JX7WFfZA7OLoEMeqNJ/NIEp iClw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lf3OWtQTMarfh+qKkUU+h4c6HMQ0ofK4k7yhmGxtgVU=; b=SzuVGsL6tefQrLGBW+dEDkA3x8Ob5k4DCIAzOcE9rQyQ/Y5qjWcqCs2o/VE3ogpYjv v+Vz5L/T1UXOxqIAbBjatXsdi+CoiNWQlTl1dCgynalefEahJd25mbwoYhnPXnCumgZg ox+TNwsX7gGlFULHVoT1Z1WTy1rk6wKwCnOFldqigN0fPeOoK82dh6DfmpcCnGs06Ffe fvmqQj1VmxjiYSBmdaCWYF8g6BoRI+orUjutDyAlFgb49AmP3jUZSySVcTJlFRcMbNiJ Evt0OknmFAQ1Q4fVYmplXwQepzYtXyNDazxKy4WQzm9EBdma75dSsPzYTrgyzazVbqFi f4hg== X-Gm-Message-State: AOAM532N2by2/XYEsTBaCiGBYPqCkTGnPc9FG63HbuHnCktrXvn4ODlb lOD7avo66gmEjB6FKk1sJAIcr7Mr X-Google-Smtp-Source: ABdhPJyZFB1G/FH9A4ea1yRVC9wsxNuo+mlDEpj4WlbhDeCAewfVGAqiU5A0MycX/M2qOvrL95WZ2A== X-Received: by 2002:a17:90b:50e:: with SMTP id r14mr679493pjz.90.1608069927363; Tue, 15 Dec 2020 14:05:27 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id x15sm84146pfa.80.2020.12.15.14.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 14:05:26 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Sumit Semwal , Liam Mark , Laura Abbott , Brian Starkey , Hridya Valsaraju , Suren Baghdasaryan , Sandeep Patil , Daniel Mentz , Chris Goldsworthy , =?utf-8?q?=C3=98rjan_Eide?= , Robin Murphy , Ezequiel Garcia , Simon Ser , James Jones , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [RFC][PATCH 2/3] dma-buf: heaps: Add a WARN_ON should the vmap_cnt go negative Date: Tue, 15 Dec 2020 22:05:20 +0000 Message-Id: <20201215220521.118318-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201215220521.118318-1-john.stultz@linaro.org> References: <20201215220521.118318-1-john.stultz@linaro.org> MIME-Version: 1.0 We shouldn't vunmap more then we vmap, but if we do, make sure we complain loudly. Cc: Sumit Semwal Cc: Liam Mark Cc: Laura Abbott Cc: Brian Starkey Cc: Hridya Valsaraju Cc: Suren Baghdasaryan Cc: Sandeep Patil Cc: Daniel Mentz Cc: Chris Goldsworthy Cc: Ørjan Eide Cc: Robin Murphy Cc: Ezequiel Garcia Cc: Simon Ser Cc: James Jones Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Suggested-by: Suren Baghdasaryan Signed-off-by: John Stultz --- drivers/dma-buf/heaps/cma_heap.c | 1 + drivers/dma-buf/heaps/system_heap.c | 1 + 2 files changed, 2 insertions(+) -- 2.17.1 diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c index 5e7c3436310c..877353e8014f 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -231,6 +231,7 @@ static void cma_heap_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) struct cma_heap_buffer *buffer = dmabuf->priv; mutex_lock(&buffer->lock); + WARN_ON(buffer->vmap_cnt == 0); if (!--buffer->vmap_cnt) { vunmap(buffer->vaddr); buffer->vaddr = NULL; diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 405351aad2a8..2321c91891f6 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -273,6 +273,7 @@ static void system_heap_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) struct system_heap_buffer *buffer = dmabuf->priv; mutex_lock(&buffer->lock); + WARN_ON(buffer->vmap_cnt == 0); if (!--buffer->vmap_cnt) { vunmap(buffer->vaddr); buffer->vaddr = NULL;