Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

IIO: Support oversampling_ratio configuration in IIO node #2354

Merged
merged 1 commit into from
Feb 16, 2017

Conversation

guchaojie
Copy link
Contributor

Signed-off-by: Gu Chaojie [email protected]

@guchaojie guchaojie force-pushed the master branch 2 times, most recently from b620098 to 89de6e9 Compare January 22, 2017 07:45
@guchaojie
Copy link
Contributor Author

@ceolin @edersondisouza @fulong82 @laykuanloon This PR is for issue #2330 please have a review. Thanks

@@ -218,6 +218,12 @@
"name": "offset"
},
{
"data_type": "direction-vector",
Copy link
Contributor

@laykuanloon laykuanloon Jan 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "data_type" should be "sol_str_table" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In iio.json, data_type cannot be sol_str_table here, please check https://github.com/solettaproject/soletta/blob/master/src/lib/common/include/sol-types.h


if (craft_filename_path(path, sizeof(path), CHANNEL_OVERSAMPLING_RATIO_DEVICE_PATH,
device->device_id, iter->key)) {
if (sol_util_write_file(path, "%d", iter->val) > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magnetometer have 3 items in sol_str_table, this only write the 1st item and return ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is OK for us to test BMP280. Yes, this will result into magnet bugs. I will fix it.

Copy link
Contributor

@laykuanloon laykuanloon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check

{ }
};

mdata->iio_base.config.oversampling_ratio_table = table;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong and will lead to memory issues!

The table variable will no longer exists when magnet_open() exit, therefore mdata->iio_base.config.oversampling_ratio_table will point to an invalid area!

{ }
};

mdata->iio_base.config.oversampling_ratio_table = table;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same problem

{ }
};

mdata->iio_base.config.oversampling_ratio_table = table;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same problem

char path[PATH_MAX];
struct sol_str_table *iter;

SOL_NULL_CHECK(device, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a public API. Do you really need to make this check here?

Copy link
Contributor Author

@guchaojie guchaojie Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES, check the input parameter pointer in function "iio_set_sampling_frequency" too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as @cabelitos said this does not make sense. There is only one place where this function is called and you have already checked this parameter there. It's looking redundant.

@guchaojie
Copy link
Contributor Author

@ceolin @edersondisouza @fulong82 @laykuanloon This PR is for issue #2330 According to your first round comments, update the PR and have a review, please. Thanks

device->device_id, iter->key)) {
if (sol_util_write_file(path, "%d", iter->val) <= 0)
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

craft_filename_path fails is not an error ? you are only returning false when sol_util_write_file fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified it.

SOL_NULL_CHECK(mdata->iio_base.config.oversampling_ratio_table, -ENOMEM);

table = mdata->iio_base.config.oversampling_ratio_table;
table->key = strdup("in_magn_x_");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to check the return of strdup, it can lead to a segv because you doing in the next line a strlen with it.

Since you'll need to do this with the others elements, you can create a macro here to avoid repeat code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified it.

ret = snprintf(mdata->iio_base.config.sampling_frequency_name,
sizeof(mdata->iio_base.config.sampling_frequency_name), "%s", "in_temp_");
SOL_INT_CHECK_GOTO(ret, >= (int)sizeof(mdata->iio_base.config.sampling_frequency_name), err);
SOL_INT_CHECK_GOTO(ret, < 0, err);
Copy link
Contributor

@ceolin ceolin Jan 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but we have a macro called SOL_EXP_CHECK_GOTO that an be used here to avoid two checks.


table = mdata->iio_base.config.oversampling_ratio_table;
table->key = strdup("in_temp_");
table->len = strlen(table->key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


table = mdata->iio_base.config.oversampling_ratio_table;
table->key = strdup("in_pressure_");
table->len = strlen(table->key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito

@guchaojie
Copy link
Contributor Author

@ceolin @edersondisouza @fulong82 @laykuanloon This PR is for issue #2330 According to your comments, update the PR and have a review, please. Thanks

@peijiajames
Copy link

@ceolin @cabelitos @laykuanloon any more comments for the PR? We want to have this for BMP/BME 280 support in Soletta.

@cabelitos
Copy link
Contributor

I guess we're fine.
@ceolin what do you think?

@ceolin
Copy link
Contributor

ceolin commented Feb 16, 2017

yep, looks good.

@ceolin ceolin merged commit fc1ceb1 into solettaproject:master Feb 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants