BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mangoh-drivers
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
mangoh-drivers
Commits
c386d785
Commit
c386d785
authored
Feb 14, 2018
by
David Frey
Committed by
David Clark
Feb 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use devm_* to ease LED driver resource management
parent
59b38930
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
29 deletions
+16
-29
led.c
linux_kernel_modules/led/led.c
+16
-29
No files found.
linux_kernel_modules/led/led.c
View file @
c386d785
...
...
@@ -46,69 +46,56 @@ static int led_probe(struct platform_device *pdev)
if
(
!
pdata
)
{
ret
=
-
EINVAL
;
dev_err
(
*
pdev
->
dev
,
"Required platform data not provided
\n
"
);
goto
err_no_fre
e
;
dev_err
(
&
pdev
->
dev
,
"Required platform data not provided
\n
"
);
goto
don
e
;
}
dev
=
kzalloc
(
sizeof
(
*
dev
),
GFP_KERNEL
);
if
(
!
dev
)
goto
err_out
;
dev
=
devm_kzalloc
(
&
pdev
->
dev
,
sizeof
(
*
dev
),
GFP_KERNEL
);
if
(
!
dev
)
{
ret
=
-
ENOMEM
;
goto
done
;
}
dev
->
pdev
=
pdev
;
atomic_set
(
&
dev
->
val
,
0
);
dev
->
gpio
=
pdata
->
gpio
;
ret
=
gpio_request
(
dev
->
gpio
,
dev_name
(
&
pdev
->
dev
));
ret
=
devm_gpio_request
(
&
pdev
->
dev
,
dev
->
gpio
,
dev_name
(
&
pdev
->
dev
));
if
(
ret
)
{
dev_err
(
&
pdev
->
dev
,
"failed to request LED gpio
\n
"
);
goto
err_out
;
goto
done
;
}
ret
=
gpio_direction_output
(
dev
->
gpio
,
atomic_read
(
&
dev
->
val
));
if
(
ret
)
{
dev_err
(
&
pdev
->
dev
,
"failed to set LED gpio as output
\n
"
);
goto
free_gpio
;
goto
done
;
}
ret
=
device_create_file
(
&
pdev
->
dev
,
&
dev_attr_led
);
if
(
ret
)
{
dev_err
(
&
pdev
->
dev
,
"failed to create led sysfs entry
\n
"
);
goto
free_gpio
;
goto
done
;
}
platform_set_drvdata
(
pdev
,
dev
);
return
ret
;
free_gpio:
gpio_direction_input
(
dev
->
gpio
);
gpio_free
(
dev
->
gpio
);
err_out:
if
(
dev
)
kfree
(
dev
);
err_no_free:
done:
return
ret
;
}
static
int
led_remove
(
struct
platform_device
*
pdev
)
{
struct
led_device
*
dev
=
platform_get_drvdata
(
pdev
);
int
ret
;
struct
led_device
*
led
=
dev_get_drvdata
(
&
pdev
->
dev
);
dev_info
(
&
pdev
->
dev
,
"%s(): remove
\n
"
,
__func__
);
/* remove sysfs files */
device_remove_file
(
&
pdev
->
dev
,
&
dev_attr_led
);
ret
=
gpio_direction_input
(
dev
->
gpio
);
if
(
ret
)
dev_err
(
&
pdev
->
dev
,
"failed to set LED gpio as input
\n
"
);
gpio_free
(
dev
->
gpio
);
kfree
(
dev
);
/* Turn off the LED as the device is removed */
gpio_set_value_cansleep
(
led
->
gpio
,
0
);
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment