From patchwork Mon Dec 14 19:04:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 556586 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A86F71402C9 for ; Tue, 15 Dec 2015 06:04:55 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=XORfAEyB; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932118AbbLNTEl (ORCPT ); Mon, 14 Dec 2015 14:04:41 -0500 Received: from mail-pf0-f181.google.com ([209.85.192.181]:34845 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932081AbbLNTEk (ORCPT ); Mon, 14 Dec 2015 14:04:40 -0500 Received: by pff63 with SMTP id 63so15760972pff.2 for ; Mon, 14 Dec 2015 11:04:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=HKoHJpdtP7KcNe/EAQBQJNUNlVJS9UAL8eXkuigt3sU=; b=XORfAEyBbcoFHMBvwk6VMvZYG4uHB0T+yP7/Kq6fR3la7ewJt9sE7rAZOKPxzwYjq3 IzkAaqMbegoCGwPN4JrG4ylhbtAq+r0teAzS2HJHttTbveIP5V4BfRLVHTp17TCndk9R 4Dwm8IhRPis5UFjX2KA3IBJy5G4c3FCKM8t7/cBOv6yX+ruzR/iXOKE5DAAZbKENF0Wm 3RJ+0Uxd4cjilhTrkP/+0/hbCFredR0/FFEdjkUAk8OzzH1DA0af5K4itzC3ZlviKuzs Ffte4l7B9FtH8zZLBBCR4U3QyRn4eFEMaNjOQJN8IHbU1ovGXpaij3gQOGda8kj0ouoS hknQ== 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; bh=HKoHJpdtP7KcNe/EAQBQJNUNlVJS9UAL8eXkuigt3sU=; b=ZkNKp/W+0cYc14OP58dj31TMhTX7LWZYQr2c90TmAOuYVTcq7CSOuhfgU0vP/ytHGh L/4CHgSjEsIRr1YSH2G8Rh6yitK+OrCEp620BMWj34wIIVXyFaVb+xhzssSybgsHI+6M R7t07wMK15EOAEebMkZ66BkqLiwDKMfR1KeozRdoHunaS8MXODBhp4ivioHJR+0eKf2f 6NFTT4eqpUZn3m9QnRFAjjXS6trMcdJNFbr8Sc6TWQOsYJY2ThJBZ29bbdFP8ZWTfohl bLzJSVVq2x3cQjJZ54fnEZQM2UnHnTu7KebXsoz/kpoH7OgNR/MVl5Iqyyos3OP6l+eX nt8Q== X-Gm-Message-State: ALoCoQlPSvfSJ/QPo4Iy2gSIETpBxDCMBXrfURqUQ+8FsIt+/5oMI2JLxfmx7kCePWAJAh0IPswqoSygYX6Gnx9gDba/NWaVPA== X-Received: by 10.98.71.138 with SMTP id p10mr38834982pfi.61.1450119880323; Mon, 14 Dec 2015 11:04:40 -0800 (PST) Received: from rajatja.mtv.corp.google.com ([172.18.65.137]) by smtp.gmail.com with ESMTPSA id q84sm22175407pfi.39.2015.12.14.11.04.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Dec 2015 11:04:39 -0800 (PST) From: Rajat Jain To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: linux-pci@vger.kernel.org, rajatxjain@gmail.com, Rajat Jain Subject: [PATCH] kobject: Ensure child's resources get released before parent's resources Date: Mon, 14 Dec 2015 11:04:11 -0800 Message-Id: <1450119851-28190-1-git-send-email-rajatja@google.com> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org If the only remaining reference to a parent, is the one taken by the child (in kobject_add_internal()), then when the last reference to the child goes away, both child and its parents shall be released. However, currently the resources of parent get released first, followed by the child's resources: kobject_cleanup(child) .... kobject_del(child) .... kobject_put(child->parent) -> results in parent's release() ... child->kobj_type->release() -> Child's release() This is a problem because the child's release() method may still need to use parent resources or memory for its own cleanup. E.g. child may need parent pointer for dma_free_coherent() etc. Signed-off-by: Rajat Jain Signed-off-by: Rajat Jain --- resending after an email address that bounced. lib/kobject.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/kobject.c b/lib/kobject.c index 7cbccd2..8f325ac 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -616,6 +616,7 @@ static void kobject_cleanup(struct kobject *kobj) { struct kobj_type *t = get_ktype(kobj); const char *name = kobj->name; + struct kobject *parent = kobj->parent; pr_debug("kobject: '%s' (%p): %s, parent %p\n", kobject_name(kobj), kobj, __func__, kobj->parent); @@ -632,6 +633,8 @@ static void kobject_cleanup(struct kobject *kobj) kobject_uevent(kobj, KOBJ_REMOVE); } + kobject_get(parent); + /* remove from sysfs if the caller did not do it */ if (kobj->state_in_sysfs) { pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n", @@ -645,6 +648,8 @@ static void kobject_cleanup(struct kobject *kobj) t->release(kobj); } + kobject_put(parent); + /* free name if we allocated it */ if (name) { pr_debug("kobject: '%s': free name\n", name);