Skip to content

Commit dc8f6d2

Browse files
committed
drivers/sensors:Fixed O_DIRECT flag triggering rpmsg cross-core
Fixes the issue of cross-core IPC being triggered when using O_DIRECT in non-cross-core scenarios. Signed-off-by: likun17 <likun17@xiaomi.com>
1 parent 695847c commit dc8f6d2

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

drivers/sensors/sensor.c

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ static int sensor_open(FAR struct file *filep)
613613
goto errout_with_lock;
614614
}
615615

616-
if (lower->ops->open)
616+
if ((filep->f_oflags & O_DIRECT) == 0 && lower->ops->open)
617617
{
618618
ret = lower->ops->open(lower, filep);
619619
if (ret < 0)
@@ -622,31 +622,32 @@ static int sensor_open(FAR struct file *filep)
622622
}
623623
}
624624

625-
if ((filep->f_oflags & O_DIRECT) == 0)
625+
/* Using the O_DIRECT flag will prevent cross-core operations,
626+
* allowing for direct I/O operations.
627+
*/
628+
629+
if (filep->f_oflags & O_RDOK)
626630
{
627-
if (filep->f_oflags & O_RDOK)
631+
if (upper->state.nsubscribers == 0 && lower->ops->activate)
628632
{
629-
if (upper->state.nsubscribers == 0 && lower->ops->activate)
633+
ret = lower->ops->activate(lower, filep, true);
634+
if (ret < 0)
630635
{
631-
ret = lower->ops->activate(lower, filep, true);
632-
if (ret < 0)
633-
{
634-
goto errout_with_open;
635-
}
636+
goto errout_with_open;
636637
}
637-
638-
user->role |= SENSOR_ROLE_RD;
639-
upper->state.nsubscribers++;
640638
}
641639

642-
if (filep->f_oflags & O_WROK)
640+
user->role |= SENSOR_ROLE_RD;
641+
upper->state.nsubscribers++;
642+
}
643+
644+
if (filep->f_oflags & O_WROK)
645+
{
646+
user->role |= SENSOR_ROLE_WR;
647+
upper->state.nadvertisers++;
648+
if (filep->f_oflags & SENSOR_PERSIST)
643649
{
644-
user->role |= SENSOR_ROLE_WR;
645-
upper->state.nadvertisers++;
646-
if (filep->f_oflags & SENSOR_PERSIST)
647-
{
648-
lower->persist = true;
649-
}
650+
lower->persist = true;
650651
}
651652
}
652653

@@ -695,7 +696,7 @@ static int sensor_close(FAR struct file *filep)
695696
int ret = 0;
696697

697698
nxrmutex_lock(&upper->lock);
698-
if (lower->ops->close)
699+
if ((filep->f_oflags & O_DIRECT) == 0 && lower->ops->close)
699700
{
700701
ret = lower->ops->close(lower, filep);
701702
if (ret < 0)
@@ -705,21 +706,22 @@ static int sensor_close(FAR struct file *filep)
705706
}
706707
}
707708

708-
if ((filep->f_oflags & O_DIRECT) == 0)
709+
/* Using the O_DIRECT flag will prevent cross-core operations,
710+
* allowing for direct I/O operations.
711+
*/
712+
713+
if (filep->f_oflags & O_RDOK)
709714
{
710-
if (filep->f_oflags & O_RDOK)
715+
upper->state.nsubscribers--;
716+
if (upper->state.nsubscribers == 0 && lower->ops->activate)
711717
{
712-
upper->state.nsubscribers--;
713-
if (upper->state.nsubscribers == 0 && lower->ops->activate)
714-
{
715-
lower->ops->activate(lower, filep, false);
716-
}
718+
lower->ops->activate(lower, filep, false);
717719
}
720+
}
718721

719-
if (filep->f_oflags & O_WROK)
720-
{
721-
upper->state.nadvertisers--;
722-
}
722+
if (filep->f_oflags & O_WROK)
723+
{
724+
upper->state.nadvertisers--;
723725
}
724726

725727
list_delete(&user->node);

0 commit comments

Comments
 (0)