return !(runflags & COMEDI_SRF_BUSY_MASK);
 }
 
+bool comedi_can_auto_free_spriv(struct comedi_subdevice *s)
+{
+       unsigned runflags = __comedi_get_subdevice_runflags(s);
+
+       return runflags & COMEDI_SRF_FREE_SPRIV;
+}
+
+/**
+ * comedi_set_spriv_auto_free - mark subdevice private data as freeable
+ * @s: comedi_subdevice struct
+ *
+ * Mark the subdevice as having a pointer to private data that can be
+ * automatically freed by the comedi core during the detach.
+ */
+void comedi_set_spriv_auto_free(struct comedi_subdevice *s)
+{
+       __comedi_set_subdevice_runflags(s, COMEDI_SRF_FREE_SPRIV);
+}
+EXPORT_SYMBOL_GPL(comedi_set_spriv_auto_free);
+
 /**
- * comedi_alloc_spriv() - Allocate memory for the subdevice private data.
+ * comedi_alloc_spriv - Allocate memory for the subdevice private data.
  * @s: comedi_subdevice struct
  * @size: size of the memory to allocate
  *
 {
        s->private = kzalloc(size, GFP_KERNEL);
        if (s->private)
-               s->runflags |= COMEDI_SRF_FREE_SPRIV;
+               comedi_set_spriv_auto_free(s);
        return s->private;
 }
 EXPORT_SYMBOL_GPL(comedi_alloc_spriv);
 
                struct comedi_subdevice *s);
 unsigned int comedi_buf_write_n_allocated(struct comedi_subdevice *s);
 void comedi_device_cancel_all(struct comedi_device *dev);
+bool comedi_can_auto_free_spriv(struct comedi_subdevice *s);
 
 extern unsigned int comedi_default_buf_size_kb;
 extern unsigned int comedi_default_buf_maxsize_kb;
 
 bool comedi_is_subdevice_running(struct comedi_subdevice *s);
 
 void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size);
+void comedi_set_spriv_auto_free(struct comedi_subdevice *s);
 
 int comedi_check_chanlist(struct comedi_subdevice *s,
                          int n,
 
        if (dev->subdevices) {
                for (i = 0; i < dev->n_subdevices; i++) {
                        s = &dev->subdevices[i];
-                       if (s->runflags & COMEDI_SRF_FREE_SPRIV)
+                       if (comedi_can_auto_free_spriv(s))
                                kfree(s->private);
                        comedi_free_subdevice_minor(s);
                        if (s->async) {
 
         * There could be multiple timers so this driver does not
         * use dev->pacer to save the i8254 pointer. Instead,
         * comedi_8254_subdevice_init() saved the i8254 pointer in
-        * s->private. Set the runflag bit so that the core will
-        * automatically free it when the driver is detached.
+        * s->private.  Mark the subdevice as having private data
+        * to be automatically freed when the device is detached.
         */
-       s->runflags |= COMEDI_SRF_FREE_SPRIV;
+       comedi_set_spriv_auto_free(s);
 
        /* Initialize channels. */
        if (board->has_clk_gat_sce) {