@@ -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,28 @@ static int sensor_open(FAR struct file *filep)
622622 }
623623 }
624624
625- if (( filep -> f_oflags & O_DIRECT ) == 0 )
625+ if (filep -> f_oflags & O_RDOK )
626626 {
627- if (filep -> f_oflags & O_RDOK )
627+ if (upper -> state . nsubscribers == 0 && lower -> ops -> activate )
628628 {
629- if (upper -> state .nsubscribers == 0 && lower -> ops -> activate )
629+ ret = lower -> ops -> activate (lower , filep , true);
630+ if (ret < 0 )
630631 {
631- ret = lower -> ops -> activate (lower , filep , true);
632- if (ret < 0 )
633- {
634- goto errout_with_open ;
635- }
632+ goto errout_with_open ;
636633 }
637-
638- user -> role |= SENSOR_ROLE_RD ;
639- upper -> state .nsubscribers ++ ;
640634 }
641635
642- if (filep -> f_oflags & O_WROK )
636+ user -> role |= SENSOR_ROLE_RD ;
637+ upper -> state .nsubscribers ++ ;
638+ }
639+
640+ if (filep -> f_oflags & O_WROK )
641+ {
642+ user -> role |= SENSOR_ROLE_WR ;
643+ upper -> state .nadvertisers ++ ;
644+ if (filep -> f_oflags & SENSOR_PERSIST )
643645 {
644- user -> role |= SENSOR_ROLE_WR ;
645- upper -> state .nadvertisers ++ ;
646- if (filep -> f_oflags & SENSOR_PERSIST )
647- {
648- lower -> persist = true;
649- }
646+ lower -> persist = true;
650647 }
651648 }
652649
@@ -695,7 +692,7 @@ static int sensor_close(FAR struct file *filep)
695692 int ret = 0 ;
696693
697694 nxrmutex_lock (& upper -> lock );
698- if (lower -> ops -> close )
695+ if (( filep -> f_oflags & O_DIRECT ) == 0 && lower -> ops -> close )
699696 {
700697 ret = lower -> ops -> close (lower , filep );
701698 if (ret < 0 )
@@ -705,21 +702,18 @@ static int sensor_close(FAR struct file *filep)
705702 }
706703 }
707704
708- if (( filep -> f_oflags & O_DIRECT ) == 0 )
705+ if (filep -> f_oflags & O_RDOK )
709706 {
710- if (filep -> f_oflags & O_RDOK )
707+ upper -> state .nsubscribers -- ;
708+ if (upper -> state .nsubscribers == 0 && lower -> ops -> activate )
711709 {
712- upper -> state .nsubscribers -- ;
713- if (upper -> state .nsubscribers == 0 && lower -> ops -> activate )
714- {
715- lower -> ops -> activate (lower , filep , false);
716- }
710+ lower -> ops -> activate (lower , filep , false);
717711 }
712+ }
718713
719- if (filep -> f_oflags & O_WROK )
720- {
721- upper -> state .nadvertisers -- ;
722- }
714+ if (filep -> f_oflags & O_WROK )
715+ {
716+ upper -> state .nadvertisers -- ;
723717 }
724718
725719 list_delete (& user -> node );
0 commit comments