@@ -58,6 +58,7 @@ struct aspeed_lpc_snoop_model_data {
58
58
};
59
59
60
60
struct aspeed_lpc_snoop_channel {
61
+ bool enabled ;
61
62
struct kfifo fifo ;
62
63
wait_queue_head_t wq ;
63
64
struct miscdevice miscdev ;
@@ -190,6 +191,9 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
190
191
const struct aspeed_lpc_snoop_model_data * model_data =
191
192
of_device_get_match_data (dev );
192
193
194
+ if (WARN_ON (lpc_snoop -> chan [channel ].enabled ))
195
+ return - EBUSY ;
196
+
193
197
init_waitqueue_head (& lpc_snoop -> chan [channel ].wq );
194
198
/* Create FIFO datastructure */
195
199
rc = kfifo_alloc (& lpc_snoop -> chan [channel ].fifo ,
@@ -236,6 +240,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
236
240
regmap_update_bits (lpc_snoop -> regmap , HICRB ,
237
241
hicrb_en , hicrb_en );
238
242
243
+ lpc_snoop -> chan [channel ].enabled = true;
244
+
239
245
return 0 ;
240
246
241
247
err_misc_deregister :
@@ -248,6 +254,9 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
248
254
static void aspeed_lpc_disable_snoop (struct aspeed_lpc_snoop * lpc_snoop ,
249
255
int channel )
250
256
{
257
+ if (!lpc_snoop -> chan [channel ].enabled )
258
+ return ;
259
+
251
260
switch (channel ) {
252
261
case 0 :
253
262
regmap_update_bits (lpc_snoop -> regmap , HICR5 ,
@@ -263,6 +272,8 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
263
272
return ;
264
273
}
265
274
275
+ lpc_snoop -> chan [channel ].enabled = false;
276
+ /* Consider improving safety wrt concurrent reader(s) */
266
277
misc_deregister (& lpc_snoop -> chan [channel ].miscdev );
267
278
kfifo_free (& lpc_snoop -> chan [channel ].fifo );
268
279
}
0 commit comments