@@ -59,6 +59,7 @@ struct aspeed_lpc_snoop_model_data {
5959};
6060
6161struct aspeed_lpc_snoop_channel {
62+ bool enabled ;
6263 struct kfifo fifo ;
6364 wait_queue_head_t wq ;
6465 struct miscdevice miscdev ;
@@ -191,6 +192,9 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
191192 const struct aspeed_lpc_snoop_model_data * model_data =
192193 of_device_get_match_data (dev );
193194
195+ if (WARN_ON (lpc_snoop -> chan [channel ].enabled ))
196+ return - EBUSY ;
197+
194198 init_waitqueue_head (& lpc_snoop -> chan [channel ].wq );
195199 /* Create FIFO datastructure */
196200 rc = kfifo_alloc (& lpc_snoop -> chan [channel ].fifo ,
@@ -237,6 +241,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
237241 regmap_update_bits (lpc_snoop -> regmap , HICRB ,
238242 hicrb_en , hicrb_en );
239243
244+ lpc_snoop -> chan [channel ].enabled = true;
245+
240246 return 0 ;
241247
242248err_misc_deregister :
@@ -249,6 +255,9 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
249255static void aspeed_lpc_disable_snoop (struct aspeed_lpc_snoop * lpc_snoop ,
250256 int channel )
251257{
258+ if (!lpc_snoop -> chan [channel ].enabled )
259+ return ;
260+
252261 switch (channel ) {
253262 case 0 :
254263 regmap_update_bits (lpc_snoop -> regmap , HICR5 ,
@@ -264,6 +273,8 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
264273 return ;
265274 }
266275
276+ lpc_snoop -> chan [channel ].enabled = false;
277+ /* Consider improving safety wrt concurrent reader(s) */
267278 misc_deregister (& lpc_snoop -> chan [channel ].miscdev );
268279 kfifo_free (& lpc_snoop -> chan [channel ].fifo );
269280}
0 commit comments