@@ -74,20 +74,25 @@ static int session_device_notify(SessionDevice *sd, enum SessionDeviceNotificati
7474 return r ;
7575
7676 switch (type ) {
77+
7778 case SESSION_DEVICE_RESUME :
7879 r = sd_bus_message_append (m , "uuh" , major , minor , sd -> fd );
7980 if (r < 0 )
8081 return r ;
8182 break ;
83+
8284 case SESSION_DEVICE_TRY_PAUSE :
8385 t = "pause" ;
8486 break ;
87+
8588 case SESSION_DEVICE_PAUSE :
8689 t = "force" ;
8790 break ;
91+
8892 case SESSION_DEVICE_RELEASE :
8993 t = "gone" ;
9094 break ;
95+
9196 default :
9297 return - EINVAL ;
9398 }
@@ -120,24 +125,18 @@ static int sd_eviocrevoke(int fd) {
120125}
121126
122127static int sd_drmsetmaster (int fd ) {
123- int r ;
124-
125128 assert (fd >= 0 );
126129
127- r = ioctl (fd , DRM_IOCTL_SET_MASTER , 0 );
128- if (r < 0 )
130+ if (ioctl (fd , DRM_IOCTL_SET_MASTER , 0 ) < 0 )
129131 return - errno ;
130132
131133 return 0 ;
132134}
133135
134136static int sd_drmdropmaster (int fd ) {
135- int r ;
136-
137137 assert (fd >= 0 );
138138
139- r = ioctl (fd , DRM_IOCTL_DROP_MASTER , 0 );
140- if (r < 0 )
139+ if (ioctl (fd , DRM_IOCTL_DROP_MASTER , 0 ) < 0 )
141140 return - errno ;
142141
143142 return 0 ;
@@ -146,36 +145,37 @@ static int sd_drmdropmaster(int fd) {
146145static int session_device_open (SessionDevice * sd , bool active ) {
147146 int fd , r ;
148147
148+ assert (sd );
149149 assert (sd -> type != DEVICE_TYPE_UNKNOWN );
150+ assert (sd -> node );
150151
151152 /* open device and try to get an udev_device from it */
152153 fd = open (sd -> node , O_RDWR |O_CLOEXEC |O_NOCTTY |O_NONBLOCK );
153154 if (fd < 0 )
154155 return - errno ;
155156
156157 switch (sd -> type ) {
158+
157159 case DEVICE_TYPE_DRM :
158160 if (active ) {
159- /* Weird legacy DRM semantics might return an error
160- * even though we're master. No way to detect that so
161- * fail at all times and let caller retry in inactive
162- * state. */
161+ /* Weird legacy DRM semantics might return an error even though we're master. No way to detect
162+ * that so fail at all times and let caller retry in inactive state. */
163163 r = sd_drmsetmaster (fd );
164164 if (r < 0 ) {
165165 close_nointr (fd );
166166 return r ;
167167 }
168- } else {
169- /* DRM-Master is granted to the first user who opens a
170- * device automatically (ughh, racy!). Hence, we just
171- * drop DRM-Master in case we were the first. */
168+ } else
169+ /* DRM-Master is granted to the first user who opens a device automatically (ughh,
170+ * racy!). Hence, we just drop DRM-Master in case we were the first. */
172171 sd_drmdropmaster (fd );
173- }
174172 break ;
173+
175174 case DEVICE_TYPE_EVDEV :
176175 if (!active )
177176 sd_eviocrevoke (fd );
178177 break ;
178+
179179 case DEVICE_TYPE_UNKNOWN :
180180 default :
181181 /* fallback for devices wihout synchronizations */
@@ -195,26 +195,27 @@ static int session_device_start(SessionDevice *sd) {
195195 return 0 ;
196196
197197 switch (sd -> type ) {
198+
198199 case DEVICE_TYPE_DRM :
199- /* Device is kept open. Simply call drmSetMaster() and hope
200- * there is no-one else. In case it fails, we keep the device
201- * paused. Maybe at some point we have a drmStealMaster(). */
200+ /* Device is kept open. Simply call drmSetMaster() and hope there is no-one else. In case it fails, we
201+ * keep the device paused. Maybe at some point we have a drmStealMaster(). */
202202 r = sd_drmsetmaster (sd -> fd );
203203 if (r < 0 )
204204 return r ;
205205 break ;
206+
206207 case DEVICE_TYPE_EVDEV :
207- /* Evdev devices are revoked while inactive. Reopen it and we
208- * are fine. */
208+ /* Evdev devices are revoked while inactive. Reopen it and we are fine. */
209209 r = session_device_open (sd , true);
210210 if (r < 0 )
211211 return r ;
212- /* For evdev devices, the file descriptor might be left
213- * uninitialized. This might happen while resuming into a
214- * session and logind has been restarted right before. */
212+
213+ /* For evdev devices, the file descriptor might be left uninitialized. This might happen while resuming
214+ * into a session and logind has been restarted right before. */
215215 safe_close (sd -> fd );
216216 sd -> fd = r ;
217217 break ;
218+
218219 case DEVICE_TYPE_UNKNOWN :
219220 default :
220221 /* fallback for devices wihout synchronizations */
0 commit comments