Re: request_firmware API exhaust memory

Tomas Winkler
2010-04-21T22:22:55Z

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

On Mon, Apr 19, 2010 at 5:59 PM, Greg KH <greg@kroah.com> wrote:
> On Mon, Apr 19, 2010 at 03:20:34PM +0300, Tomas Winkler wrote:
>> Lately we've been developing a device that rather more extensively
>> used request_firmware API in load and also using pm_notifiers to load
>> firmware.
>
> Do you have a pointer to your driver source anywhere that shows how you
> are trying to use the firmware api in this manner?

I've attached a very simple test driver I'm using. Just wanted to
eliminate anything else.
Bellow is a little script that loads and releases the firmware. My
previous observation was wrong.
The free memory gradually decreases regardless of number or dangling
udevd forks, which are eventually collected if the sleep period is
long enough ~10s.

testfw=${1:-test-fw600k.fw}
count=${2:-100}
s=${3:-10}
for ((i=0; i<$count ; i++)) ; do
echo -n $testfw > /sys/devices/platform/fw-test/load_fw
echo -n 1 > /sys/devices/platform/fw-test/release_fw
sleep $s
grep MemFree /proc/meminfo | awk '{print $2}'
ps auxwww | grep udevd | wc -l
done

Thanks
Tomas

[-- Attachment #2: fw-test.c --]
[-- Type: application/octet-stream, Size: 3305 bytes --]

/*
* fw-test.c -FW Test Driver
*
*
* Copyright (C) 2010, Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* TODO
*
*/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/backlight.h>
#include <linux/platform_device.h>
#include <linux/sysfs.h>
#include <linux/firmware.h>

MODULE_AUTHOR("Tomas Winkler");
MODULE_DESCRIPTION("Firmware API Test Driver");
MODULE_LICENSE("GPL");

struct fw_test_dev {
struct platform_device *p_dev;
struct mutex mutex;
const struct firmware *fw;
};

static struct fw_test_dev fw_test;

static ssize_t load_fw(struct device *d, struct device_attribute *attr,
const char *buf, size_t count)
{
struct fw_test_dev *priv = &fw_test;
ssize_t ret;

mutex_lock(&fw_test.mutex);
ret = request_firmware(&priv->fw, buf, d);
if (ret)
printk(KERN_ERR "request fail %s ret=%zd", buf, ret);
else
ret = count;
mutex_unlock(&fw_test.mutex);

printk(KERN_INFO "FW-TEST LOAD");
return ret;
}

static ssize_t release_fw(struct device *d, struct device_attribute *attr,
const char *buf, size_t count)
{
struct fw_test_dev *priv = &fw_test;

mutex_lock(&fw_test.mutex);
release_firmware(priv->fw);
priv->fw = NULL;
mutex_unlock(&fw_test.mutex);
printk(KERN_INFO "FW-TEST RELEASE");

return count;
}

static DEVICE_ATTR(load_fw, S_IWUGO, NULL, load_fw);

static DEVICE_ATTR(release_fw, S_IWUGO, NULL, release_fw);

static struct attribute *fw_test_sysfs_entries[] = {
&dev_attr_load_fw.attr,
&dev_attr_release_fw.attr,
NULL
};

static struct attribute_group fw_test_attribute_group = {
.name = NULL, /* put in device directory */
.attrs = fw_test_sysfs_entries,
};

static void fw_test_exit(void)
{

sysfs_remove_group(&fw_test.p_dev->dev.kobj, &fw_test_attribute_group);
platform_device_unregister(fw_test.p_dev);
printk(KERN_INFO "FW API Test Driver Unloaded");

return;
}

static int __init fw_test_init(void)
{

int ret;

mutex_init(&fw_test.mutex);

fw_test.p_dev = platform_device_register_simple("fw-test", -1, NULL, 0);
if (IS_ERR(fw_test.p_dev)) {
ret = PTR_ERR(fw_test.p_dev);
printk(KERN_ERR "unable to register platform device\n");
fw_test.p_dev = NULL;
fw_test_exit();
return ret;
}
ret = sysfs_create_group(&fw_test.p_dev->dev.kobj, &fw_test_attribute_group);
if (ret) {
printk(KERN_ERR "Failed to allocate SYSFS entry");
fw_test.p_dev = NULL;
fw_test_exit();
return ret;
}
printk(KERN_INFO "FW API Test Driver Loaded");
return 0;

}

module_init(fw_test_init);
module_exit(fw_test_exit);