Use dev_kzmalloc, remove .release entry point.
Signed-off-by: Gwendal Grignou <[email protected]>
---
drivers/mfd/cros_ec_dev.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index eafd06f62a3a..45d42511a3e5 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -262,13 +262,6 @@ static const struct file_operations fops = {
#endif
};
-static void __remove(struct device *dev)
-{
- struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
- class_dev);
- kfree(ec);
-}
-
static void cros_ec_sensors_register(struct cros_ec_dev *ec)
{
/*
@@ -388,7 +381,7 @@ static int ec_device_probe(struct platform_device *pdev)
int retval = -ENOMEM;
struct device *dev = &pdev->dev;
struct cros_ec_platform *ec_platform = dev_get_platdata(dev);
- struct cros_ec_dev *ec = kzalloc(sizeof(*ec), GFP_KERNEL);
+ struct cros_ec_dev *ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL);
if (!ec)
return retval;
@@ -410,7 +403,6 @@ static int ec_device_probe(struct platform_device *pdev)
ec->class_dev.devt = MKDEV(ec_major, pdev->id);
ec->class_dev.class = &cros_class;
ec->class_dev.parent = dev;
- ec->class_dev.release = __remove;
retval = dev_set_name(&ec->class_dev, "%s", ec_platform->ec_name);
if (retval) {
--
2.17.0.441.gb46fe60e1d-goog
Hi Gwendal,
2018-05-10 1:06 GMT+02:00 Gwendal Grignou <[email protected]>:
> Use dev_kzmalloc, remove .release entry point.
>
> Signed-off-by: Gwendal Grignou <[email protected]>
> ---
> drivers/mfd/cros_ec_dev.c | 10 +---------
> 1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
> index eafd06f62a3a..45d42511a3e5 100644
> --- a/drivers/mfd/cros_ec_dev.c
> +++ b/drivers/mfd/cros_ec_dev.c
> @@ -262,13 +262,6 @@ static const struct file_operations fops = {
> #endif
> };
>
> -static void __remove(struct device *dev)
> -{
> - struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
> - class_dev);
> - kfree(ec);
> -}
> -
> static void cros_ec_sensors_register(struct cros_ec_dev *ec)
> {
> /*
> @@ -388,7 +381,7 @@ static int ec_device_probe(struct platform_device *pdev)
> int retval = -ENOMEM;
> struct device *dev = &pdev->dev;
> struct cros_ec_platform *ec_platform = dev_get_platdata(dev);
> - struct cros_ec_dev *ec = kzalloc(sizeof(*ec), GFP_KERNEL);
> + struct cros_ec_dev *ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL);
>
> if (!ec)
> return retval;
> @@ -410,7 +403,6 @@ static int ec_device_probe(struct platform_device *pdev)
> ec->class_dev.devt = MKDEV(ec_major, pdev->id);
> ec->class_dev.class = &cros_class;
> ec->class_dev.parent = dev;
> - ec->class_dev.release = __remove;
>
> retval = dev_set_name(&ec->class_dev, "%s", ec_platform->ec_name);
> if (retval) {
> --
> 2.17.0.441.gb46fe60e1d-goog
>
The patch looks good to me, however, the patch doesn't apply cleanly
if you have [1] already applied, and if not, then is this patch ([2])
which doesn't apply cleanly. To not have interdependencies I'd suggest
apply first this patch and remove the following from [1]
diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index eafd06f62a3a..cad12da7f884 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -264,8 +264,8 @@ static const struct file_operations fops = {
static void __remove(struct device *dev)
{
- struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
- class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
+
kfree(ec);
}
With this change, [1] can go through the Benson tree and [2] through
Lee tree independently. With the above change feel free to add my
Reviewed-by: Enric Balletbo i Serra <[email protected]>
If you want I can do this rework for you.
Best regards,
Enric
[1] https://patchwork.kernel.org/patch/10390959/
[2] https://patchwork.kernel.org/patch/10390965/
Move to_cros_ec_dev macro to cros_ec.h and use it when the private ec
object is needed from device object.
Signed-off-by: Gwendal Grignou <[email protected]>
---
Change since v1:
Remove changes in cros_ec_dev.c to avoid inter-dependencies.
drivers/platform/chrome/cros_ec_lightbar.c | 21 +++++++--------------
drivers/platform/chrome/cros_ec_sysfs.c | 2 --
drivers/platform/chrome/cros_ec_vbc.c | 9 +++------
include/linux/mfd/cros_ec.h | 2 ++
4 files changed, 12 insertions(+), 22 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c
index 6ea79d495aa2..68193bb53383 100644
--- a/drivers/platform/chrome/cros_ec_lightbar.c
+++ b/drivers/platform/chrome/cros_ec_lightbar.c
@@ -170,8 +170,7 @@ static ssize_t version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
uint32_t version = 0, flags = 0;
- struct cros_ec_dev *ec = container_of(dev,
- struct cros_ec_dev, class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
int ret;
ret = lb_throttle();
@@ -193,8 +192,7 @@ static ssize_t brightness_store(struct device *dev,
struct cros_ec_command *msg;
int ret;
unsigned int val;
- struct cros_ec_dev *ec = container_of(dev,
- struct cros_ec_dev, class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
if (kstrtouint(buf, 0, &val))
return -EINVAL;
@@ -238,8 +236,7 @@ static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr,
{
struct ec_params_lightbar *param;
struct cros_ec_command *msg;
- struct cros_ec_dev *ec = container_of(dev,
- struct cros_ec_dev, class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
unsigned int val[4];
int ret, i = 0, j = 0, ok = 0;
@@ -311,8 +308,7 @@ static ssize_t sequence_show(struct device *dev,
struct ec_response_lightbar *resp;
struct cros_ec_command *msg;
int ret;
- struct cros_ec_dev *ec = container_of(dev,
- struct cros_ec_dev, class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
msg = alloc_lightbar_cmd_msg(ec);
if (!msg)
@@ -439,8 +435,7 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
struct cros_ec_command *msg;
unsigned int num;
int ret, len;
- struct cros_ec_dev *ec = container_of(dev,
- struct cros_ec_dev, class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
for (len = 0; len < count; len++)
if (!isalnum(buf[len]))
@@ -488,8 +483,7 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
int extra_bytes, max_size, ret;
struct ec_params_lightbar *param;
struct cros_ec_command *msg;
- struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
- class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
/*
* We might need to reject the program for size reasons. The EC
@@ -599,8 +593,7 @@ static umode_t cros_ec_lightbar_attrs_are_visible(struct kobject *kobj,
struct attribute *a, int n)
{
struct device *dev = container_of(kobj, struct device, kobj);
- struct cros_ec_dev *ec = container_of(dev,
- struct cros_ec_dev, class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct platform_device *pdev = to_platform_device(ec->dev);
struct cros_ec_platform *pdata = pdev->dev.platform_data;
int is_cros_ec;
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index 5a6db3fe213a..f34a50121064 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -34,8 +34,6 @@
#include <linux/types.h>
#include <linux/uaccess.h>
-#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)
-
/* Accessor functions */
static ssize_t reboot_show(struct device *dev,
diff --git a/drivers/platform/chrome/cros_ec_vbc.c b/drivers/platform/chrome/cros_ec_vbc.c
index 6d38e6b08334..5356f26bc022 100644
--- a/drivers/platform/chrome/cros_ec_vbc.c
+++ b/drivers/platform/chrome/cros_ec_vbc.c
@@ -29,8 +29,7 @@ static ssize_t vboot_context_read(struct file *filp, struct kobject *kobj,
loff_t pos, size_t count)
{
struct device *dev = container_of(kobj, struct device, kobj);
- struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
- class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_device *ecdev = ec->ec_dev;
struct ec_params_vbnvcontext *params;
struct cros_ec_command *msg;
@@ -70,8 +69,7 @@ static ssize_t vboot_context_write(struct file *filp, struct kobject *kobj,
loff_t pos, size_t count)
{
struct device *dev = container_of(kobj, struct device, kobj);
- struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
- class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct cros_ec_device *ecdev = ec->ec_dev;
struct ec_params_vbnvcontext *params;
struct cros_ec_command *msg;
@@ -111,8 +109,7 @@ static umode_t cros_ec_vbc_is_visible(struct kobject *kobj,
struct bin_attribute *a, int n)
{
struct device *dev = container_of(kobj, struct device, kobj);
- struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
- class_dev);
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct device_node *np = ec->ec_dev->dev->of_node;
if (IS_ENABLED(CONFIG_OF) && np) {
diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index 4ff0cec979b0..4270972adb94 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -197,6 +197,8 @@ struct cros_ec_dev {
u32 features[2];
};
+#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)
+
/**
* cros_ec_suspend - Handle a suspend operation for the ChromeOS EC device
*
--
2.17.0.921.gf22659ad46-goog
Hi Gwendal,
2018-05-30 18:04 GMT+02:00 Gwendal Grignou <[email protected]>:
> Move to_cros_ec_dev macro to cros_ec.h and use it when the private ec
> object is needed from device object.
>
> Signed-off-by: Gwendal Grignou <[email protected]>
> ---
> Change since v1:
> Remove changes in cros_ec_dev.c to avoid inter-dependencies.
>
> drivers/platform/chrome/cros_ec_lightbar.c | 21 +++++++--------------
> drivers/platform/chrome/cros_ec_sysfs.c | 2 --
> drivers/platform/chrome/cros_ec_vbc.c | 9 +++------
> include/linux/mfd/cros_ec.h | 2 ++
> 4 files changed, 12 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c
> index 6ea79d495aa2..68193bb53383 100644
> --- a/drivers/platform/chrome/cros_ec_lightbar.c
> +++ b/drivers/platform/chrome/cros_ec_lightbar.c
> @@ -170,8 +170,7 @@ static ssize_t version_show(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> uint32_t version = 0, flags = 0;
> - struct cros_ec_dev *ec = container_of(dev,
> - struct cros_ec_dev, class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
> int ret;
>
> ret = lb_throttle();
> @@ -193,8 +192,7 @@ static ssize_t brightness_store(struct device *dev,
> struct cros_ec_command *msg;
> int ret;
> unsigned int val;
> - struct cros_ec_dev *ec = container_of(dev,
> - struct cros_ec_dev, class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
>
> if (kstrtouint(buf, 0, &val))
> return -EINVAL;
> @@ -238,8 +236,7 @@ static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr,
> {
> struct ec_params_lightbar *param;
> struct cros_ec_command *msg;
> - struct cros_ec_dev *ec = container_of(dev,
> - struct cros_ec_dev, class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
> unsigned int val[4];
> int ret, i = 0, j = 0, ok = 0;
>
> @@ -311,8 +308,7 @@ static ssize_t sequence_show(struct device *dev,
> struct ec_response_lightbar *resp;
> struct cros_ec_command *msg;
> int ret;
> - struct cros_ec_dev *ec = container_of(dev,
> - struct cros_ec_dev, class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
>
> msg = alloc_lightbar_cmd_msg(ec);
> if (!msg)
> @@ -439,8 +435,7 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
> struct cros_ec_command *msg;
> unsigned int num;
> int ret, len;
> - struct cros_ec_dev *ec = container_of(dev,
> - struct cros_ec_dev, class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
>
> for (len = 0; len < count; len++)
> if (!isalnum(buf[len]))
> @@ -488,8 +483,7 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
> int extra_bytes, max_size, ret;
> struct ec_params_lightbar *param;
> struct cros_ec_command *msg;
> - struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
> - class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
>
> /*
> * We might need to reject the program for size reasons. The EC
> @@ -599,8 +593,7 @@ static umode_t cros_ec_lightbar_attrs_are_visible(struct kobject *kobj,
> struct attribute *a, int n)
> {
> struct device *dev = container_of(kobj, struct device, kobj);
> - struct cros_ec_dev *ec = container_of(dev,
> - struct cros_ec_dev, class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
> struct platform_device *pdev = to_platform_device(ec->dev);
> struct cros_ec_platform *pdata = pdev->dev.platform_data;
> int is_cros_ec;
> diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
> index 5a6db3fe213a..f34a50121064 100644
> --- a/drivers/platform/chrome/cros_ec_sysfs.c
> +++ b/drivers/platform/chrome/cros_ec_sysfs.c
> @@ -34,8 +34,6 @@
> #include <linux/types.h>
> #include <linux/uaccess.h>
>
> -#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)
> -
> /* Accessor functions */
>
> static ssize_t reboot_show(struct device *dev,
> diff --git a/drivers/platform/chrome/cros_ec_vbc.c b/drivers/platform/chrome/cros_ec_vbc.c
> index 6d38e6b08334..5356f26bc022 100644
> --- a/drivers/platform/chrome/cros_ec_vbc.c
> +++ b/drivers/platform/chrome/cros_ec_vbc.c
> @@ -29,8 +29,7 @@ static ssize_t vboot_context_read(struct file *filp, struct kobject *kobj,
> loff_t pos, size_t count)
> {
> struct device *dev = container_of(kobj, struct device, kobj);
> - struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
> - class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
> struct cros_ec_device *ecdev = ec->ec_dev;
> struct ec_params_vbnvcontext *params;
> struct cros_ec_command *msg;
> @@ -70,8 +69,7 @@ static ssize_t vboot_context_write(struct file *filp, struct kobject *kobj,
> loff_t pos, size_t count)
> {
> struct device *dev = container_of(kobj, struct device, kobj);
> - struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
> - class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
> struct cros_ec_device *ecdev = ec->ec_dev;
> struct ec_params_vbnvcontext *params;
> struct cros_ec_command *msg;
> @@ -111,8 +109,7 @@ static umode_t cros_ec_vbc_is_visible(struct kobject *kobj,
> struct bin_attribute *a, int n)
> {
> struct device *dev = container_of(kobj, struct device, kobj);
> - struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
> - class_dev);
> + struct cros_ec_dev *ec = to_cros_ec_dev(dev);
> struct device_node *np = ec->ec_dev->dev->of_node;
>
> if (IS_ENABLED(CONFIG_OF) && np) {
> diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
> index 4ff0cec979b0..4270972adb94 100644
> --- a/include/linux/mfd/cros_ec.h
> +++ b/include/linux/mfd/cros_ec.h
> @@ -197,6 +197,8 @@ struct cros_ec_dev {
> u32 features[2];
> };
>
> +#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)
> +
> /**
> * cros_ec_suspend - Handle a suspend operation for the ChromeOS EC device
> *
> --
> 2.17.0.921.gf22659ad46-goog
>
The patch looks good to me.
Reviewed-by: Enric Balletbo i Serra <[email protected]>
Thanks,
Enric
Use dev_kzmalloc, remove .release entry point.
Signed-off-by: Gwendal Grignou <[email protected]>
---
Change sinc v1:
- Readd __remove to avoid a warning when loaded as a module.
drivers/mfd/cros_ec_dev.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index 1d6dc5c7a19d..81466264f7fc 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -262,12 +262,7 @@ static const struct file_operations fops = {
#endif
};
-static void __remove(struct device *dev)
-{
- struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
- class_dev);
- kfree(ec);
-}
+static void __remove(struct device *dev) { }
static void cros_ec_sensors_register(struct cros_ec_dev *ec)
{
@@ -392,7 +387,7 @@ static int ec_device_probe(struct platform_device *pdev)
int retval = -ENOMEM;
struct device *dev = &pdev->dev;
struct cros_ec_platform *ec_platform = dev_get_platdata(dev);
- struct cros_ec_dev *ec = kzalloc(sizeof(*ec), GFP_KERNEL);
+ struct cros_ec_dev *ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL);
if (!ec)
return retval;
@@ -414,7 +409,6 @@ static int ec_device_probe(struct platform_device *pdev)
ec->class_dev.devt = MKDEV(ec_major, pdev->id);
ec->class_dev.class = &cros_class;
ec->class_dev.parent = dev;
- ec->class_dev.release = __remove;
retval = dev_set_name(&ec->class_dev, "%s", ec_platform->ec_name);
if (retval) {
--
2.17.0.921.gf22659ad46-goog
Hi Gwendal,
On Wed, May 30, 2018 at 09:04:13AM -0700, Gwendal Grignou wrote:
> Move to_cros_ec_dev macro to cros_ec.h and use it when the private ec
> object is needed from device object.
>
> Signed-off-by: Gwendal Grignou <[email protected]>
Applied to platform/chrome for v4.18.
FYI, Lee, I'll add the new macro in cros_ec.h through my tree. Looks to
merge clean with mfd's changes this time.
Thanks,
Benson
--
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]
On Wed, 30 May 2018, Gwendal Grignou wrote:
> Use dev_kzmalloc, remove .release entry point.
>
> Signed-off-by: Gwendal Grignou <[email protected]>
> ---
> Change sinc v1:
> - Readd __remove to avoid a warning when loaded as a module.
>
> drivers/mfd/cros_ec_dev.c | 10 ++--------
> 1 file changed, 2 insertions(+), 8 deletions(-)
Applied, thanks.
--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
On Wed, 30 May 2018, Gwendal Grignou wrote:
> Use dev_kzmalloc, remove .release entry point.
>
> Signed-off-by: Gwendal Grignou <[email protected]>
> ---
> Change sinc v1:
> - Readd __remove to avoid a warning when loaded as a module.
>
> drivers/mfd/cros_ec_dev.c | 10 ++--------
> 1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
> index 1d6dc5c7a19d..81466264f7fc 100644
> --- a/drivers/mfd/cros_ec_dev.c
> +++ b/drivers/mfd/cros_ec_dev.c
> @@ -262,12 +262,7 @@ static const struct file_operations fops = {
> #endif
> };
>
> -static void __remove(struct device *dev)
> -{
> - struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev,
> - class_dev);
> - kfree(ec);
> -}
> +static void __remove(struct device *dev) { }
I missed this line when reviewing.
Why are you keeping the function around?
As a result, we now suffer with a build warning:
drivers/mfd/cros_ec_dev.c:265:13: warning: '__remove' defined but not used [-Wunused-function]
static void __remove(struct device *dev) { }
Can I just remove the line? What are the ramifications of doing so?
Please reply swiftly, so resolve this issue in good time.
--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog