[2/2] lib: fwts_ac_adapter: fix failing to find AC directory
diff mbox series

Message ID 20190110053407.9154-2-alex.hung@canonical.com
State Superseded
Headers show
Series
  • [1/2] lib: fwts_ac_adapter: fix readdir(ac_power_dir) failing
Related show

Commit Message

Alex Hung Jan. 10, 2019, 5:34 a.m. UTC
Some BIOS names adapter device "AC" which has length of 2. As a result,
it always fails to get AC directory. This removes the condition to have
directory name greater than 2.

Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 src/lib/src/fwts_ac_adapter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Colin Ian King Jan. 10, 2019, 9:13 a.m. UTC | #1
On 10/01/2019 05:34, Alex Hung wrote:
> Some BIOS names adapter device "AC" which has length of 2. As a result,
> it always fails to get AC directory. This removes the condition to have
> directory name greater than 2.
> 
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/lib/src/fwts_ac_adapter.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/lib/src/fwts_ac_adapter.c b/src/lib/src/fwts_ac_adapter.c
> index de2242a2..fbf75b24 100644
> --- a/src/lib/src/fwts_ac_adapter.c
> +++ b/src/lib/src/fwts_ac_adapter.c
> @@ -103,7 +103,7 @@ int fwts_ac_adapter_get_state(const int state, int *matching, int *not_matching)
>  		return FWTS_ERROR;
>  	do {
>  		entry = readdir(ac_power_dir);
> -		if (entry && strlen(entry->d_name) > 2) {

I believe that code was to skip the "." and ".." links. I think the code
should have been:

		if (entry && entry->d_name[0] != '.') {



> +		if (entry) {
>  			char path[PATH_MAX];
>  			char *data;
>  
>
ivanhu Jan. 14, 2019, 9:56 a.m. UTC | #2
On 1/10/19 1:34 PM, Alex Hung wrote:
> Some BIOS names adapter device "AC" which has length of 2. As a result,
> it always fails to get AC directory. This removes the condition to have
> directory name greater than 2.
>
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/lib/src/fwts_ac_adapter.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_ac_adapter.c b/src/lib/src/fwts_ac_adapter.c
> index de2242a2..fbf75b24 100644
> --- a/src/lib/src/fwts_ac_adapter.c
> +++ b/src/lib/src/fwts_ac_adapter.c
> @@ -103,7 +103,7 @@ int fwts_ac_adapter_get_state(const int state, int *matching, int *not_matching)
>  		return FWTS_ERROR;
>  	do {
>  		entry = readdir(ac_power_dir);
> -		if (entry && strlen(entry->d_name) > 2) {
> +		if (entry) {
>  			char path[PATH_MAX];
>  			char *data;
>  


Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch
diff mbox series

diff --git a/src/lib/src/fwts_ac_adapter.c b/src/lib/src/fwts_ac_adapter.c
index de2242a2..fbf75b24 100644
--- a/src/lib/src/fwts_ac_adapter.c
+++ b/src/lib/src/fwts_ac_adapter.c
@@ -103,7 +103,7 @@  int fwts_ac_adapter_get_state(const int state, int *matching, int *not_matching)
 		return FWTS_ERROR;
 	do {
 		entry = readdir(ac_power_dir);
-		if (entry && strlen(entry->d_name) > 2) {
+		if (entry) {
 			char path[PATH_MAX];
 			char *data;