Navigation Menu

Skip to content

Commit

Permalink
drivers/lsm6dsl: eliminate and correct casts
Browse files Browse the repository at this point in the history
Converting phydat_t* to lsm6dsl_3d_data_t* is not correct, but it happened
to just work because the first struct member of phydat_t will be used.

Furthermore, casting &res[0] to int16_t* is wrong. Again, it just happened
to work.
  • Loading branch information
Kees Bakker committed Jan 6, 2019
1 parent b77c802 commit d8edf6d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/lsm6dsl/lsm6dsl_saul.c
Expand Up @@ -25,7 +25,7 @@

static int read_acc(const void *dev, phydat_t *res)
{
int ret = lsm6dsl_read_acc((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res);
int ret = lsm6dsl_read_acc((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res->val);
if (ret < 0) {
return -ECANCELED;
}
Expand All @@ -38,7 +38,7 @@ static int read_acc(const void *dev, phydat_t *res)

static int read_gyro(const void *dev, phydat_t *res)
{
int ret = lsm6dsl_read_gyro((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res);
int ret = lsm6dsl_read_gyro((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res->val);
if (ret < 0) {
return -ECANCELED;
}
Expand All @@ -51,7 +51,7 @@ static int read_gyro(const void *dev, phydat_t *res)

static int read_temp(const void *dev, phydat_t *res)
{
if (lsm6dsl_read_temp((const lsm6dsl_t *)dev, (int16_t *)&res[0]) < 0) {
if (lsm6dsl_read_temp((const lsm6dsl_t *)dev, &res->val[0]) < 0) {
return -ECANCELED;
}
res->scale = -2;
Expand Down

0 comments on commit d8edf6d

Please sign in to comment.