All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@01.org, Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	kbuild-all@01.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: Re: [PATCH 4/6] drivers: base: Introducing software nodes to the firmware node framework
Date: Wed, 7 Nov 2018 07:39:33 +0300	[thread overview]
Message-ID: <20181107043933.wqszrfajrfy6hv7u@mwanda> (raw)
In-Reply-To: <20181105145928.46819-5-heikki.krogerus@linux.intel.com>

Hi Heikki,

url:    https://github.com/0day-ci/linux/commits/Heikki-Krogerus/device-property-Introducing-software-nodes/20181106-031310

smatch warnings:
drivers/base/swnode.c:391 fwnode_create_software_node() error: dereferencing freed memory 'swnode'

# https://github.com/0day-ci/linux/commit/a8c9678ea46a0171baed68e4ec355a9b3f967458
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout a8c9678ea46a0171baed68e4ec355a9b3f967458
vim +/swnode +391 drivers/base/swnode.c

a8c9678e Heikki Krogerus 2018-11-05  365  
a8c9678e Heikki Krogerus 2018-11-05  366  struct fwnode_handle *
a8c9678e Heikki Krogerus 2018-11-05  367  fwnode_create_software_node(const struct property_entry *properties,
a8c9678e Heikki Krogerus 2018-11-05  368  			    const struct fwnode_handle *parent)
a8c9678e Heikki Krogerus 2018-11-05  369  {
a8c9678e Heikki Krogerus 2018-11-05  370  	struct software_node *p = NULL;
a8c9678e Heikki Krogerus 2018-11-05  371  	struct software_node *swnode;
a8c9678e Heikki Krogerus 2018-11-05  372  	char node_name[20];
a8c9678e Heikki Krogerus 2018-11-05  373  	int ret;
a8c9678e Heikki Krogerus 2018-11-05  374  
a8c9678e Heikki Krogerus 2018-11-05  375  	if (parent) {
a8c9678e Heikki Krogerus 2018-11-05  376  		if (IS_ERR(parent))
a8c9678e Heikki Krogerus 2018-11-05  377  			return ERR_CAST(parent);
a8c9678e Heikki Krogerus 2018-11-05  378  		if (!is_software_node(parent))
a8c9678e Heikki Krogerus 2018-11-05  379  			return ERR_PTR(-EINVAL);
a8c9678e Heikki Krogerus 2018-11-05  380  		p = to_software_node(parent);
a8c9678e Heikki Krogerus 2018-11-05  381  	}
a8c9678e Heikki Krogerus 2018-11-05  382  
a8c9678e Heikki Krogerus 2018-11-05  383  	swnode = kzalloc(sizeof(*swnode), GFP_KERNEL);
a8c9678e Heikki Krogerus 2018-11-05  384  	if (!swnode)
a8c9678e Heikki Krogerus 2018-11-05  385  		return ERR_PTR(-ENOMEM);
a8c9678e Heikki Krogerus 2018-11-05  386  
a8c9678e Heikki Krogerus 2018-11-05  387  	swnode->id = ida_simple_get(p ? &p->child_ids : &swnode_root_ids, 0, 0,
a8c9678e Heikki Krogerus 2018-11-05  388  				    GFP_KERNEL);
a8c9678e Heikki Krogerus 2018-11-05  389  	if (swnode->id < 0) {
a8c9678e Heikki Krogerus 2018-11-05  390  		kfree(swnode);
                                                              ^^^^^^
a8c9678e Heikki Krogerus 2018-11-05 @391  		return ERR_PTR(swnode->id);
                                                                       ^^^^^^^^^^
a8c9678e Heikki Krogerus 2018-11-05  392  	}
a8c9678e Heikki Krogerus 2018-11-05  393  
a8c9678e Heikki Krogerus 2018-11-05  394  	sprintf(node_name, "node%d", swnode->id);
a8c9678e Heikki Krogerus 2018-11-05  395  
a8c9678e Heikki Krogerus 2018-11-05  396  	swnode->kobj.kset = swnode_kset;
a8c9678e Heikki Krogerus 2018-11-05  397  	swnode->fwnode.ops = &software_node_ops;
a8c9678e Heikki Krogerus 2018-11-05  398  
a8c9678e Heikki Krogerus 2018-11-05  399  	ida_init(&swnode->child_ids);
a8c9678e Heikki Krogerus 2018-11-05  400  	INIT_LIST_HEAD(&swnode->entry);
a8c9678e Heikki Krogerus 2018-11-05  401  	INIT_LIST_HEAD(&swnode->children);
a8c9678e Heikki Krogerus 2018-11-05  402  	swnode->parent = p;
a8c9678e Heikki Krogerus 2018-11-05  403  
a8c9678e Heikki Krogerus 2018-11-05  404  	if (p)
a8c9678e Heikki Krogerus 2018-11-05  405  		list_add_tail(&swnode->entry, &p->children);
a8c9678e Heikki Krogerus 2018-11-05  406  
a8c9678e Heikki Krogerus 2018-11-05  407  	ret = kobject_init_and_add(&swnode->kobj, &software_node_type,
a8c9678e Heikki Krogerus 2018-11-05  408  				   p ? &p->kobj : NULL, node_name);
a8c9678e Heikki Krogerus 2018-11-05  409  	if (ret) {
a8c9678e Heikki Krogerus 2018-11-05  410  		kobject_put(&swnode->kobj);
a8c9678e Heikki Krogerus 2018-11-05  411  		return ERR_PTR(ret);
a8c9678e Heikki Krogerus 2018-11-05  412  	}
a8c9678e Heikki Krogerus 2018-11-05  413  
a8c9678e Heikki Krogerus 2018-11-05  414  	ret = software_node_register_properties(swnode, properties);
a8c9678e Heikki Krogerus 2018-11-05  415  	if (ret) {
a8c9678e Heikki Krogerus 2018-11-05  416  		kobject_put(&swnode->kobj);
a8c9678e Heikki Krogerus 2018-11-05  417  		return ERR_PTR(ret);
a8c9678e Heikki Krogerus 2018-11-05  418  	}
a8c9678e Heikki Krogerus 2018-11-05  419  
a8c9678e Heikki Krogerus 2018-11-05  420  	kobject_uevent(&swnode->kobj, KOBJ_ADD);
a8c9678e Heikki Krogerus 2018-11-05  421  	return &swnode->fwnode;
a8c9678e Heikki Krogerus 2018-11-05  422  }
a8c9678e Heikki Krogerus 2018-11-05  423  EXPORT_SYMBOL_GPL(fwnode_create_software_node);
a8c9678e Heikki Krogerus 2018-11-05  424  

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@01.org, Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: kbuild-all@01.org, "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org
Subject: Re: [PATCH 4/6] drivers: base: Introducing software nodes to the firmware node framework
Date: Wed, 7 Nov 2018 07:39:33 +0300	[thread overview]
Message-ID: <20181107043933.wqszrfajrfy6hv7u@mwanda> (raw)
In-Reply-To: <20181105145928.46819-5-heikki.krogerus@linux.intel.com>

Hi Heikki,

url:    https://github.com/0day-ci/linux/commits/Heikki-Krogerus/device-property-Introducing-software-nodes/20181106-031310

smatch warnings:
drivers/base/swnode.c:391 fwnode_create_software_node() error: dereferencing freed memory 'swnode'

# https://github.com/0day-ci/linux/commit/a8c9678ea46a0171baed68e4ec355a9b3f967458
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout a8c9678ea46a0171baed68e4ec355a9b3f967458
vim +/swnode +391 drivers/base/swnode.c

a8c9678e Heikki Krogerus 2018-11-05  365  
a8c9678e Heikki Krogerus 2018-11-05  366  struct fwnode_handle *
a8c9678e Heikki Krogerus 2018-11-05  367  fwnode_create_software_node(const struct property_entry *properties,
a8c9678e Heikki Krogerus 2018-11-05  368  			    const struct fwnode_handle *parent)
a8c9678e Heikki Krogerus 2018-11-05  369  {
a8c9678e Heikki Krogerus 2018-11-05  370  	struct software_node *p = NULL;
a8c9678e Heikki Krogerus 2018-11-05  371  	struct software_node *swnode;
a8c9678e Heikki Krogerus 2018-11-05  372  	char node_name[20];
a8c9678e Heikki Krogerus 2018-11-05  373  	int ret;
a8c9678e Heikki Krogerus 2018-11-05  374  
a8c9678e Heikki Krogerus 2018-11-05  375  	if (parent) {
a8c9678e Heikki Krogerus 2018-11-05  376  		if (IS_ERR(parent))
a8c9678e Heikki Krogerus 2018-11-05  377  			return ERR_CAST(parent);
a8c9678e Heikki Krogerus 2018-11-05  378  		if (!is_software_node(parent))
a8c9678e Heikki Krogerus 2018-11-05  379  			return ERR_PTR(-EINVAL);
a8c9678e Heikki Krogerus 2018-11-05  380  		p = to_software_node(parent);
a8c9678e Heikki Krogerus 2018-11-05  381  	}
a8c9678e Heikki Krogerus 2018-11-05  382  
a8c9678e Heikki Krogerus 2018-11-05  383  	swnode = kzalloc(sizeof(*swnode), GFP_KERNEL);
a8c9678e Heikki Krogerus 2018-11-05  384  	if (!swnode)
a8c9678e Heikki Krogerus 2018-11-05  385  		return ERR_PTR(-ENOMEM);
a8c9678e Heikki Krogerus 2018-11-05  386  
a8c9678e Heikki Krogerus 2018-11-05  387  	swnode->id = ida_simple_get(p ? &p->child_ids : &swnode_root_ids, 0, 0,
a8c9678e Heikki Krogerus 2018-11-05  388  				    GFP_KERNEL);
a8c9678e Heikki Krogerus 2018-11-05  389  	if (swnode->id < 0) {
a8c9678e Heikki Krogerus 2018-11-05  390  		kfree(swnode);
                                                              ^^^^^^
a8c9678e Heikki Krogerus 2018-11-05 @391  		return ERR_PTR(swnode->id);
                                                                       ^^^^^^^^^^
a8c9678e Heikki Krogerus 2018-11-05  392  	}
a8c9678e Heikki Krogerus 2018-11-05  393  
a8c9678e Heikki Krogerus 2018-11-05  394  	sprintf(node_name, "node%d", swnode->id);
a8c9678e Heikki Krogerus 2018-11-05  395  
a8c9678e Heikki Krogerus 2018-11-05  396  	swnode->kobj.kset = swnode_kset;
a8c9678e Heikki Krogerus 2018-11-05  397  	swnode->fwnode.ops = &software_node_ops;
a8c9678e Heikki Krogerus 2018-11-05  398  
a8c9678e Heikki Krogerus 2018-11-05  399  	ida_init(&swnode->child_ids);
a8c9678e Heikki Krogerus 2018-11-05  400  	INIT_LIST_HEAD(&swnode->entry);
a8c9678e Heikki Krogerus 2018-11-05  401  	INIT_LIST_HEAD(&swnode->children);
a8c9678e Heikki Krogerus 2018-11-05  402  	swnode->parent = p;
a8c9678e Heikki Krogerus 2018-11-05  403  
a8c9678e Heikki Krogerus 2018-11-05  404  	if (p)
a8c9678e Heikki Krogerus 2018-11-05  405  		list_add_tail(&swnode->entry, &p->children);
a8c9678e Heikki Krogerus 2018-11-05  406  
a8c9678e Heikki Krogerus 2018-11-05  407  	ret = kobject_init_and_add(&swnode->kobj, &software_node_type,
a8c9678e Heikki Krogerus 2018-11-05  408  				   p ? &p->kobj : NULL, node_name);
a8c9678e Heikki Krogerus 2018-11-05  409  	if (ret) {
a8c9678e Heikki Krogerus 2018-11-05  410  		kobject_put(&swnode->kobj);
a8c9678e Heikki Krogerus 2018-11-05  411  		return ERR_PTR(ret);
a8c9678e Heikki Krogerus 2018-11-05  412  	}
a8c9678e Heikki Krogerus 2018-11-05  413  
a8c9678e Heikki Krogerus 2018-11-05  414  	ret = software_node_register_properties(swnode, properties);
a8c9678e Heikki Krogerus 2018-11-05  415  	if (ret) {
a8c9678e Heikki Krogerus 2018-11-05  416  		kobject_put(&swnode->kobj);
a8c9678e Heikki Krogerus 2018-11-05  417  		return ERR_PTR(ret);
a8c9678e Heikki Krogerus 2018-11-05  418  	}
a8c9678e Heikki Krogerus 2018-11-05  419  
a8c9678e Heikki Krogerus 2018-11-05  420  	kobject_uevent(&swnode->kobj, KOBJ_ADD);
a8c9678e Heikki Krogerus 2018-11-05  421  	return &swnode->fwnode;
a8c9678e Heikki Krogerus 2018-11-05  422  }
a8c9678e Heikki Krogerus 2018-11-05  423  EXPORT_SYMBOL_GPL(fwnode_create_software_node);
a8c9678e Heikki Krogerus 2018-11-05  424  

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

  reply	other threads:[~2018-11-07  4:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-05 14:59 [PATCH 0/6] device property: Introducing software nodes Heikki Krogerus
2018-11-05 14:59 ` [PATCH 1/6] driver core: platform: Remove duplicated device_remove_properties() call Heikki Krogerus
2018-11-05 14:59 ` [PATCH 2/6] drivers core: Prepare support for multiple platform notifications Heikki Krogerus
2018-11-05 14:59 ` [PATCH 3/6] ACPI / glue: Add acpi_platform_notify() function Heikki Krogerus
2018-11-05 14:59 ` [PATCH 4/6] drivers: base: Introducing software nodes to the firmware node framework Heikki Krogerus
2018-11-07  4:39   ` Dan Carpenter [this message]
2018-11-07  4:39     ` Dan Carpenter
2018-11-07 12:33     ` Heikki Krogerus
2018-11-05 14:59 ` [PATCH 5/6] device property: Move device_add_properties() to swnode.c Heikki Krogerus
2018-11-05 14:59 ` [PATCH 6/6] device property: Remove struct property_set Heikki Krogerus
2018-11-06 14:46   ` Andy Shevchenko
2018-11-07 12:34     ` Heikki Krogerus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181107043933.wqszrfajrfy6hv7u@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=kbuild-all@01.org \
    --cc=kbuild@01.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.