@@ -732,6 +732,41 @@ static bool nbcon_context_can_proceed(struct nbcon_context *ctxt, struct nbcon_s
732
732
return false;
733
733
}
734
734
735
+ /**
736
+ * nbcon_can_proceed - Check whether ownership can proceed
737
+ * @wctxt: The write context that was handed to the write function
738
+ *
739
+ * Return: True if this context still owns the console. False if
740
+ * ownership was handed over or taken.
741
+ *
742
+ * It is used in nbcon_enter_unsafe() to make sure that it still owns the
743
+ * lock. Also it is used in nbcon_exit_unsafe() to eventually free the lock
744
+ * for a higher priority context which asked for the friendly handover.
745
+ *
746
+ * It can be called inside an unsafe section when the console is just
747
+ * temporary in safe state instead of exiting and entering the unsafe state.
748
+ *
749
+ * Also it can be called in the safe context before doing an expensive safe
750
+ * operation. It does not make sense to do the operation when a higher
751
+ * priority context took the lock.
752
+ *
753
+ * When this function returns false then the calling context no longer owns
754
+ * the console and is no longer allowed to go forward. In this case it must
755
+ * back out immediately and carefully. The buffer content is also no longer
756
+ * trusted since it no longer belongs to the calling context.
757
+ */
758
+ bool nbcon_can_proceed (struct nbcon_write_context * wctxt )
759
+ {
760
+ struct nbcon_context * ctxt = & ACCESS_PRIVATE (wctxt , ctxt );
761
+ struct console * con = ctxt -> console ;
762
+ struct nbcon_state cur ;
763
+
764
+ nbcon_state_read (con , & cur );
765
+
766
+ return nbcon_context_can_proceed (ctxt , & cur );
767
+ }
768
+ EXPORT_SYMBOL_GPL (nbcon_can_proceed );
769
+
735
770
#define nbcon_context_enter_unsafe (c ) __nbcon_context_update_unsafe(c, true)
736
771
#define nbcon_context_exit_unsafe (c ) __nbcon_context_update_unsafe(c, false)
737
772
@@ -782,6 +817,46 @@ static bool __nbcon_context_update_unsafe(struct nbcon_context *ctxt, bool unsaf
782
817
return nbcon_context_can_proceed (ctxt , & cur );
783
818
}
784
819
820
+ /**
821
+ * nbcon_enter_unsafe - Enter an unsafe region in the driver
822
+ * @wctxt: The write context that was handed to the write function
823
+ *
824
+ * Return: True if this context still owns the console. False if
825
+ * ownership was handed over or taken.
826
+ *
827
+ * When this function returns false then the calling context no longer owns
828
+ * the console and is no longer allowed to go forward. In this case it must
829
+ * back out immediately and carefully. The buffer content is also no longer
830
+ * trusted since it no longer belongs to the calling context.
831
+ */
832
+ bool nbcon_enter_unsafe (struct nbcon_write_context * wctxt )
833
+ {
834
+ struct nbcon_context * ctxt = & ACCESS_PRIVATE (wctxt , ctxt );
835
+
836
+ return nbcon_context_enter_unsafe (ctxt );
837
+ }
838
+ EXPORT_SYMBOL_GPL (nbcon_enter_unsafe );
839
+
840
+ /**
841
+ * nbcon_exit_unsafe - Exit an unsafe region in the driver
842
+ * @wctxt: The write context that was handed to the write function
843
+ *
844
+ * Return: True if this context still owns the console. False if
845
+ * ownership was handed over or taken.
846
+ *
847
+ * When this function returns false then the calling context no longer owns
848
+ * the console and is no longer allowed to go forward. In this case it must
849
+ * back out immediately and carefully. The buffer content is also no longer
850
+ * trusted since it no longer belongs to the calling context.
851
+ */
852
+ bool nbcon_exit_unsafe (struct nbcon_write_context * wctxt )
853
+ {
854
+ struct nbcon_context * ctxt = & ACCESS_PRIVATE (wctxt , ctxt );
855
+
856
+ return nbcon_context_exit_unsafe (ctxt );
857
+ }
858
+ EXPORT_SYMBOL_GPL (nbcon_exit_unsafe );
859
+
785
860
/**
786
861
* nbcon_emit_next_record - Emit a record in the acquired context
787
862
* @wctxt: The write context that will be handed to the write function
0 commit comments