Skip to content

Commit 6c64e1a

Browse files
committed
soc: aspeed: lpc-snoop: Rearrange channel paths
Order assignments such that tests for conditions not involving resource acquisition are ordered before those testing acquired resources, and order managed resource acquisition before unmanaged where possible. This way we minimise the amount of manual cleanup required. In the process, improve readability of the code by introducing a channel pointer that takes the place of the repeated object lookups. Acked-by: Jean Delvare <jdelvare@suse.de> Link: https://patch.msgid.link/20250616-aspeed-lpc-snoop-fixes-v2-6-3cdd59c934d3@codeconstruct.com.au Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
1 parent e88c9a7 commit 6c64e1a

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

drivers/soc/aspeed/aspeed-lpc-snoop.c

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -194,28 +194,30 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
194194
{
195195
const struct aspeed_lpc_snoop_model_data *model_data;
196196
u32 hicr5_en, snpwadr_mask, snpwadr_shift, hicrb_en;
197+
struct aspeed_lpc_snoop_channel *channel;
197198
int rc = 0;
198199

199-
if (WARN_ON(lpc_snoop->chan[index].enabled))
200+
channel = &lpc_snoop->chan[index];
201+
202+
if (WARN_ON(channel->enabled))
200203
return -EBUSY;
201204

202-
init_waitqueue_head(&lpc_snoop->chan[index].wq);
203-
/* Create FIFO datastructure */
204-
rc = kfifo_alloc(&lpc_snoop->chan[index].fifo,
205-
SNOOP_FIFO_SIZE, GFP_KERNEL);
205+
init_waitqueue_head(&channel->wq);
206+
207+
channel->miscdev.minor = MISC_DYNAMIC_MINOR;
208+
channel->miscdev.fops = &snoop_fops;
209+
channel->miscdev.parent = dev;
210+
211+
channel->miscdev.name =
212+
devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, index);
213+
if (!channel->miscdev.name)
214+
return -ENOMEM;
215+
216+
rc = kfifo_alloc(&channel->fifo, SNOOP_FIFO_SIZE, GFP_KERNEL);
206217
if (rc)
207218
return rc;
208219

209-
lpc_snoop->chan[index].miscdev.minor = MISC_DYNAMIC_MINOR;
210-
lpc_snoop->chan[index].miscdev.name =
211-
devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, index);
212-
if (!lpc_snoop->chan[index].miscdev.name) {
213-
rc = -ENOMEM;
214-
goto err_free_fifo;
215-
}
216-
lpc_snoop->chan[index].miscdev.fops = &snoop_fops;
217-
lpc_snoop->chan[index].miscdev.parent = dev;
218-
rc = misc_register(&lpc_snoop->chan[index].miscdev);
220+
rc = misc_register(&channel->miscdev);
219221
if (rc)
220222
goto err_free_fifo;
221223

@@ -246,22 +248,26 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
246248
if (model_data && model_data->has_hicrb_ensnp)
247249
regmap_update_bits(lpc_snoop->regmap, HICRB, hicrb_en, hicrb_en);
248250

249-
lpc_snoop->chan[index].enabled = true;
251+
channel->enabled = true;
250252

251253
return 0;
252254

253255
err_misc_deregister:
254-
misc_deregister(&lpc_snoop->chan[index].miscdev);
256+
misc_deregister(&channel->miscdev);
255257
err_free_fifo:
256-
kfifo_free(&lpc_snoop->chan[index].fifo);
258+
kfifo_free(&channel->fifo);
257259
return rc;
258260
}
259261

260262
__attribute__((nonnull))
261263
static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
262264
enum aspeed_lpc_snoop_index index)
263265
{
264-
if (!lpc_snoop->chan[index].enabled)
266+
struct aspeed_lpc_snoop_channel *channel;
267+
268+
channel = &lpc_snoop->chan[index];
269+
270+
if (!channel->enabled)
265271
return;
266272

267273
/* Disable interrupts along with the device */
@@ -280,10 +286,10 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
280286
return;
281287
}
282288

283-
lpc_snoop->chan[index].enabled = false;
289+
channel->enabled = false;
284290
/* Consider improving safety wrt concurrent reader(s) */
285-
misc_deregister(&lpc_snoop->chan[index].miscdev);
286-
kfifo_free(&lpc_snoop->chan[index].fifo);
291+
misc_deregister(&channel->miscdev);
292+
kfifo_free(&channel->fifo);
287293
}
288294

289295
static int aspeed_lpc_snoop_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)