From patchwork Mon Feb 3 18:16:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 24054 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9F05D202B2 for ; Mon, 3 Feb 2014 18:16:51 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id q10sf18117039pdj.2 for ; Mon, 03 Feb 2014 10:16:50 -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=bx+LUblTp42NJN2JwjPyzxV6kBTgbja8ku4+C7H+Pa4=; b=FIZd+NtGXVwaAOM8y/bbkhOJadZ0Jvcne2TjK3RB3TSNbCKljQaD1P6KyIJYzduySm PPO/kJeRZZz8i7JqNacxqssgzrKNvTKw9khk4B+sgFUV1G5IO4klMyqfpSR02m1i2aAA pmllgxTVt4fjGEXnDtoDuafWbijyEPOcjtkM/OwwX0WQxCv3f8IEZfK6SW4v4sBSaDxJ 2YeENJQ72umkw5Lq97K/N/tYwnA08hdkrivwtiqXO/hGPNmj3yhr/v2GCyLbrQDUS84r q4tl9IMa6TIQhazRLsG2czWmMMUEHwRMa6WdRCMVvxqxbULjTuWt43KYAP9s3w9QhLP/ p/yw== X-Gm-Message-State: ALoCoQnq6iY912SYLDLvoZV3fYAvZO5ROuof1gqLh0J58S9HEWXFIuSEI0o/cZ1DFKGlhqjOa3Rs X-Received: by 10.66.240.4 with SMTP id vw4mr13823655pac.10.1391451410892; Mon, 03 Feb 2014 10:16:50 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.119 with SMTP id h110ls1847420qge.54.gmail; Mon, 03 Feb 2014 10:16:50 -0800 (PST) X-Received: by 10.220.178.73 with SMTP id bl9mr200396vcb.42.1391451410781; Mon, 03 Feb 2014 10:16:50 -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 uc1si7073555vcb.53.2014.02.03.10.16.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Feb 2014 10:16:50 -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 le5so4939198vcb.2 for ; Mon, 03 Feb 2014 10:16:50 -0800 (PST) X-Received: by 10.52.185.196 with SMTP id fe4mr4910145vdc.27.1391451410699; Mon, 03 Feb 2014 10:16:50 -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 u4csp174186vcz; Mon, 3 Feb 2014 10:16:50 -0800 (PST) X-Received: by 10.66.43.135 with SMTP id w7mr38336562pal.97.1391451409804; Mon, 03 Feb 2014 10:16:49 -0800 (PST) Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com [209.85.192.171]) by mx.google.com with ESMTPS id ot3si21468495pac.340.2014.02.03.10.16.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Feb 2014 10:16:49 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.171 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.171; Received: by mail-pd0-f171.google.com with SMTP id g10so7146576pdj.30 for ; Mon, 03 Feb 2014 10:16:49 -0800 (PST) X-Received: by 10.68.211.1 with SMTP id my1mr39116140pbc.55.1391451409419; Mon, 03 Feb 2014 10:16:49 -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 y9sm150496099pas.10.2014.02.03.10.16.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Feb 2014 10:16:48 -0800 (PST) From: John Stultz To: LKML Cc: Mitchel Humpherys , Greg KH , Colin Cross , Android Kernel Team , John Stultz Subject: [PATCH 12/16] staging: ion: Make sure all clients are exposed in debugfs Date: Mon, 3 Feb 2014 10:16:24 -0800 Message-Id: <1391451388-23906-13-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391451388-23906-1-git-send-email-john.stultz@linaro.org> References: <1391451388-23906-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: Mitchel Humpherys Currently, if multiple Ion clients are created with the same name, only the first one shows up in debugfs. Rectify this by adding a monotonically-increasing serial number to the debug names of Ion clients. Cc: Greg KH Cc: Colin Cross Cc: Android Kernel Team Signed-off-by: Mitchel Humpherys [jstultz: Minor commit subject tweaks] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 47163bd..1ecbf31 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -71,6 +71,8 @@ struct ion_device { * @idr: an idr space for allocating handle ids * @lock: lock protecting the tree of handles * @name: used for debugging + * @display_name: used for debugging (unique version of @name) + * @display_serial: used for debugging (to make display_name unique) * @task: used for debugging * * A client represents a list of buffers this client may access. @@ -84,6 +86,8 @@ struct ion_client { struct idr idr; struct mutex lock; const char *name; + char *display_name; + int display_serial; struct task_struct *task; pid_t pid; struct dentry *debug_root; @@ -710,6 +714,21 @@ static const struct file_operations debug_client_fops = { .release = single_release, }; +static int ion_get_client_serial(const struct rb_root *root, + const unsigned char *name) +{ + int serial = -1; + struct rb_node *node; + for (node = rb_first(root); node; node = rb_next(node)) { + struct ion_client *client = rb_entry(node, struct ion_client, + node); + if (strcmp(client->name, name)) + continue; + serial = max(serial, client->display_serial); + } + return serial + 1; +} + struct ion_client *ion_client_create(struct ion_device *dev, const char *name) { @@ -720,6 +739,11 @@ struct ion_client *ion_client_create(struct ion_device *dev, struct ion_client *entry; pid_t pid; + if (!name) { + pr_err("%s: Name cannot be null\n", __func__); + return ERR_PTR(-EINVAL); + } + get_task_struct(current->group_leader); task_lock(current->group_leader); pid = task_pid_nr(current->group_leader); @@ -748,6 +772,13 @@ struct ion_client *ion_client_create(struct ion_device *dev, goto err_free_client; down_write(&dev->lock); + client->display_serial = ion_get_client_serial(&dev->clients, name); + client->display_name = kasprintf( + GFP_KERNEL, "%s-%d", name, client->display_serial); + if (!client->display_name) { + up_write(&dev->lock); + goto err_free_client_name; + } p = &dev->clients.rb_node; while (*p) { parent = *p; @@ -761,20 +792,22 @@ struct ion_client *ion_client_create(struct ion_device *dev, rb_link_node(&client->node, parent, p); rb_insert_color(&client->node, &dev->clients); - client->debug_root = debugfs_create_file(name, 0664, + client->debug_root = debugfs_create_file(client->display_name, 0664, dev->clients_debug_root, client, &debug_client_fops); if (!client->debug_root) { char buf[256], *path; path = dentry_path(dev->clients_debug_root, buf, 256); pr_err("Failed to create client debugfs at %s/%s\n", - path, name); + path, client->display_name); } up_write(&dev->lock); return client; +err_free_client_name: + kfree(client->name); err_free_client: kfree(client); err_put_task_struct: @@ -805,6 +838,7 @@ void ion_client_destroy(struct ion_client *client) debugfs_remove_recursive(client->debug_root); up_write(&dev->lock); + kfree(client->display_name); kfree(client->name); kfree(client); }