From patchwork Fri Dec 13 22:24:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22437 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C2EEF23FBA for ; Fri, 13 Dec 2013 22:28:06 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id vb8sf8731765obc.0 for ; Fri, 13 Dec 2013 14:28:06 -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:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=9qr1uGdGs0+Hkg9DPUh8afcO+mXKuLyjd9MVS8P2Vy4=; b=aKNwQRyZn39nWm7xh7rjOxH4K3N6xqnAnJtXgkS9yqsuIrFVXjPBriy44Hk9sKJAJl Z63D6Ay330tuwnCPkYB/Q+ycc+LeAbD7OicZFM+z6r5IiSvYbTY+lEdGNLJ3dRKMc1Jg xofBPadQ5iPHi+WcNdncKOPMzdI0peDF1uYcEcrERmmtN4MGu3HBYoQjOnGk0YdiGSi+ krzO7KbrNL6mHkZYxcspizIw6Ud39h3WzDafxsKJfOyoiJy8iise0k6e9moHcvKHdjNG C58ugoCupZfEREBDlP/fBTaXmgyNPpQBKCVZOYjkcsBQ1O+RNbjq9rVNqX13jgGl64BW Yb9A== X-Gm-Message-State: ALoCoQmbxhvME5JhjoOOO0CUaXKNIKgekcWfNdZ3Tyy6yapSS3zAqppWFIOx3mz7dXh5MSCIAO0y X-Received: by 10.182.53.165 with SMTP id c5mr1906166obp.0.1386973686347; Fri, 13 Dec 2013 14:28:06 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.58.229 with SMTP id u5ls1188063qeq.69.gmail; Fri, 13 Dec 2013 14:28:06 -0800 (PST) X-Received: by 10.58.156.106 with SMTP id wd10mr2194372veb.7.1386973686187; Fri, 13 Dec 2013 14:28:06 -0800 (PST) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id xw5si1200839vec.46.2013.12.13.14.28.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:28:06 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id ik5so1727104vcb.2 for ; Fri, 13 Dec 2013 14:28:06 -0800 (PST) X-Received: by 10.221.54.65 with SMTP id vt1mr2234767vcb.46.1386973686034; Fri, 13 Dec 2013 14:28:06 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp73598vcz; Fri, 13 Dec 2013 14:28:05 -0800 (PST) X-Received: by 10.66.142.107 with SMTP id rv11mr6108401pab.17.1386973684824; Fri, 13 Dec 2013 14:28:04 -0800 (PST) Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by mx.google.com with ESMTPS id d2si2490264pba.271.2013.12.13.14.28.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:28:04 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.42 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.220.42; Received: by mail-pa0-f42.google.com with SMTP id lj1so603035pab.1 for ; Fri, 13 Dec 2013 14:28:04 -0800 (PST) X-Received: by 10.66.246.229 with SMTP id xz5mr6001347pac.128.1386973684444; Fri, 13 Dec 2013 14:28:04 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id qz9sm7457908pbc.3.2013.12.13.14.28.03 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:28:03 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , John Stultz Subject: [PATCH 075/115] ion: remove IS_ERR_OR_NULL Date: Fri, 13 Dec 2013 14:24:49 -0800 Message-Id: <1386973529-4884-76-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Colin Cross IS_ERR_OR_NULL is often part of a bad pattern that can accidentally return 0 on error: if (IS_ERR_OR_NULL(ptr)) return PTR_ERR(ptr); It also usually means that the errors of a function are not well defined. Replace all uses in ion.c by ensure that the return type of any function in ion is an ERR_PTR. Specify that the expected return value from map_kernel or map_dma heap ops is ERR_PTR, and warn if a heap returns NULL. Signed-off-by: Colin Cross [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion.c | 28 +++++++++++++++------------- drivers/staging/android/ion/ion_priv.h | 3 +++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 93b84a9..54a00fe 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -197,7 +197,9 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, buffer->size = len; table = heap->ops->map_dma(heap, buffer); - if (IS_ERR_OR_NULL(table)) { + if (WARN_ONCE(table == NULL, "heap->ops->map_dma should return ERR_PTR on error")) + table = ERR_PTR(-EINVAL); + if (IS_ERR(table)) { heap->ops->free(buffer); kfree(buffer); return ERR_PTR(PTR_ERR(table)); @@ -389,7 +391,7 @@ static struct ion_handle *ion_handle_lookup(struct ion_client *client, if (handle->buffer == buffer) return handle; } - return NULL; + return ERR_PTR(-EINVAL); } static bool ion_handle_validate(struct ion_client *client, struct ion_handle *handle) @@ -459,7 +461,7 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len, if (!((1 << heap->id) & heap_id_mask)) continue; buffer = ion_buffer_create(heap, dev, len, align, flags); - if (!IS_ERR_OR_NULL(buffer)) + if (!IS_ERR(buffer)) break; } up_read(&dev->lock); @@ -543,7 +545,9 @@ static void *ion_buffer_kmap_get(struct ion_buffer *buffer) return buffer->vaddr; } vaddr = buffer->heap->ops->map_kernel(buffer->heap, buffer); - if (IS_ERR_OR_NULL(vaddr)) + if (WARN_ONCE(vaddr == NULL, "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++; @@ -560,7 +564,7 @@ static void *ion_handle_kmap_get(struct ion_handle *handle) return buffer->vaddr; } vaddr = ion_buffer_kmap_get(buffer); - if (IS_ERR_OR_NULL(vaddr)) + if (IS_ERR(vaddr)) return vaddr; handle->kmap_cnt++; return vaddr; @@ -954,8 +958,6 @@ static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, size_t start, mutex_unlock(&buffer->lock); if (IS_ERR(vaddr)) return PTR_ERR(vaddr); - if (!vaddr) - return -ENOMEM; return 0; } @@ -1034,7 +1036,7 @@ struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd) struct ion_handle *handle; dmabuf = dma_buf_get(fd); - if (IS_ERR_OR_NULL(dmabuf)) + if (IS_ERR(dmabuf)) return ERR_PTR(PTR_ERR(dmabuf)); /* if this memory came from ion */ @@ -1049,12 +1051,12 @@ struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd) mutex_lock(&client->lock); /* if a handle exists for this buffer just take a reference to it */ handle = ion_handle_lookup(client, buffer); - if (!IS_ERR_OR_NULL(handle)) { + if (!IS_ERR(handle)) { ion_handle_get(handle); goto end; } handle = ion_handle_create(client, buffer); - if (IS_ERR_OR_NULL(handle)) + if (IS_ERR(handle)) goto end; ion_handle_add(client, handle); end: @@ -1070,7 +1072,7 @@ static int ion_sync_for_device(struct ion_client *client, int fd) struct ion_buffer *buffer; dmabuf = dma_buf_get(fd); - if (IS_ERR_OR_NULL(dmabuf)) + if (IS_ERR(dmabuf)) return PTR_ERR(dmabuf); /* if this memory came from ion */ @@ -1204,7 +1206,7 @@ static int ion_open(struct inode *inode, struct file *file) pr_debug("%s: %d\n", __func__, __LINE__); client = ion_client_create(dev, "user"); - if (IS_ERR_OR_NULL(client)) + if (IS_ERR(client)) return PTR_ERR(client); file->private_data = client; @@ -1400,7 +1402,7 @@ struct ion_device *ion_device_create(long (*custom_ioctl) } idev->debug_root = debugfs_create_dir("ion", NULL); - if (IS_ERR_OR_NULL(idev->debug_root)) + if (!idev->debug_root) pr_err("ion: failed to create debug files.\n"); idev->custom_ioctl = custom_ioctl; diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 965471a..f263563 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -94,6 +94,9 @@ void ion_buffer_destroy(struct ion_buffer *buffer); * @map_kernel map memory to the kernel * @unmap_kernel unmap memory to the kernel * @map_user map memory to userspace + * + * allocate, phys, and map_user return 0 on success, -errno on error. + * map_dma and map_kernel return pointer on success, ERR_PTR on error. */ struct ion_heap_ops { int (*allocate) (struct ion_heap *heap,