From patchwork Thu Jan 14 18:58:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 59766 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp68304lbb; Thu, 14 Jan 2016 10:58:46 -0800 (PST) X-Received: by 10.98.31.207 with SMTP id l76mr2351275pfj.134.1452797926387; Thu, 14 Jan 2016 10:58:46 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18si10854194pfi.243.2016.01.14.10.58.46; Thu, 14 Jan 2016 10:58:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932217AbcANS6o (ORCPT + 29 others); Thu, 14 Jan 2016 13:58:44 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:33842 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932181AbcANS61 (ORCPT ); Thu, 14 Jan 2016 13:58:27 -0500 Received: by mail-pa0-f44.google.com with SMTP id uo6so365695175pac.1 for ; Thu, 14 Jan 2016 10:58:27 -0800 (PST) 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; bh=vIspG+jybIRhwMZWWbYbIvfuYBlawUQRnPLAG/C+KKU=; b=QkeiTAw7tac+7s2to34zhr+V3qm1DKR75OZVM92JScRhcMjoTFBRAgdX6atgeGZLal s1n8vaGArHyNHBFqvkOPH1PmcVoAWxPJNI9KuqeLCthn+Nv92wBJEEqYZCOeIE8tngcE DVfnvkbOHsbV9Q7N7NC8PDzBxLluv1Slrl2Iw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vIspG+jybIRhwMZWWbYbIvfuYBlawUQRnPLAG/C+KKU=; b=epgxwPGoXLRig3gRIFfeFrsRq3cCc2VbH39wqQB+Z2G0zzcD2yOmc+k140sgOcY2C/ pJ7fCobVkt1SjMGoq4VUth29TIhibqSt9GGbvywR59Ph1pqoYF4oKiiT9uoQodN/Az5p GtBfe6oQhHfl/Oi5eE/WPK32qwfqYySHkv2nuVWh5wCb1a8MuRYM9Ts+2RzWQP5L5Zw+ 6ZqGJrH/Z1Ho3FDIUa6Q0zYtbEFheE2PNze4QiIMB7uiPeUJbyjczgKB/xc/icIBVAq/ asaPlVJOOWXIg1MK4Fvh/ewsnhCptId7drYmICVn2MkaCOKUzoNGb/WJI/BOG50rd6Ro mQig== X-Gm-Message-State: ALoCoQkqjvwCs82/f3N4Fh+hU93VZEMLDbZvMOHqug/IIcChsYNbP1+9HhHQB7lYvYaL0LjtH20cK/6lyUt6vihg4Q4EzR3K6w== X-Received: by 10.66.164.196 with SMTP id ys4mr8330723pab.119.1452797907138; Thu, 14 Jan 2016 10:58:27 -0800 (PST) Received: from t430.cg.shawcable.net ([184.64.168.246]) by smtp.gmail.com with ESMTPSA id p87sm10854256pfi.94.2016.01.14.10.58.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Jan 2016 10:58:26 -0800 (PST) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Mathieu Poirier Subject: [PATCH 5/5] coresight: remove csdev's link from topology Date: Thu, 14 Jan 2016 11:58:00 -0700 Message-Id: <1452797880-4365-6-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452797880-4365-1-git-send-email-mathieu.poirier@linaro.org> References: <1452797880-4365-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In function 'coresight_unregister()', all references to the csdev that is being taken away need to be removed from the topology. Otherwise building the next coresight path from source to sink may use memory that has been released. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight.c | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) -- 2.1.4 diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index a35ca54a76c9..7e6e9ff27dd1 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -579,6 +579,50 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev) } } +static int coresight_remove_match(struct device *dev, void *data) +{ + int i; + struct coresight_device *csdev, *iterator; + struct coresight_connection *conn; + + csdev = data; + iterator = to_coresight_device(dev); + + /* No need to check oneself */ + if (csdev == iterator) + return 0; + + /* + * Circle throuch all the connection of that component. If we find + * a connection whose name matches @csdev, remove it. + */ + for (i = 0; i < iterator->nr_outport; i++) { + conn = &iterator->conns[i]; + + if (conn->child_dev == NULL) + continue; + + if (!strcmp(dev_name(&csdev->dev), conn->child_name)) { + iterator->orphan = true; + conn->child_dev = NULL; + /* No need to continue */ + break; + } + } + + /* + * Returning '0' ensures that all known component on the + * bus will be checked. + */ + return 0; +} + +static void coresight_remove_conns(struct coresight_device *csdev) +{ + bus_for_each_dev(&coresight_bustype, NULL, + csdev, coresight_remove_match); +} + /** * coresight_timeout - loop until a bit has changed to a specific state. * @addr: base address of the area of interest. @@ -717,6 +761,8 @@ EXPORT_SYMBOL_GPL(coresight_register); void coresight_unregister(struct coresight_device *csdev) { + /* Remove references of that device in the topology */ + coresight_remove_conns(csdev); device_unregister(&csdev->dev); } EXPORT_SYMBOL_GPL(coresight_unregister);