Skip to content

Commit b1e495b

Browse files
annie-likonradwilk
authored andcommitted
xen/granttable: Refactor some code
Acked-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Annie Li <annie.li@oracle.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent 0f9f5a9 commit b1e495b

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎drivers/xen/grant-table.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,17 @@ EXPORT_SYMBOL_GPL(gnttab_query_foreign_access);
257257
static int gnttab_end_foreign_access_ref_v1(grant_ref_t ref, int readonly)
258258
{
259259
u16 flags, nflags;
260+
u16 *pflags;
260261

261-
nflags = gnttab_shared.v1[ref].flags;
262+
pflags = &gnttab_shared.v1[ref].flags;
263+
nflags = *pflags;
262264
do {
263265
flags = nflags;
264266
if (flags & (GTF_reading|GTF_writing)) {
265267
printk(KERN_ALERT "WARNING: g.e. still in use!\n");
266268
return 0;
267269
}
268-
} while ((nflags = sync_cmpxchg(&gnttab_shared.v1[ref].flags, flags, 0)) != flags);
270+
} while ((nflags = sync_cmpxchg(pflags, flags, 0)) != flags);
269271

270272
return 1;
271273
}
@@ -316,20 +318,23 @@ static unsigned long gnttab_end_foreign_transfer_ref_v1(grant_ref_t ref)
316318
{
317319
unsigned long frame;
318320
u16 flags;
321+
u16 *pflags;
322+
323+
pflags = &gnttab_shared.v1[ref].flags;
319324

320325
/*
321326
* If a transfer is not even yet started, try to reclaim the grant
322327
* reference and return failure (== 0).
323328
*/
324-
while (!((flags = gnttab_shared.v1[ref].flags) & GTF_transfer_committed)) {
325-
if (sync_cmpxchg(&gnttab_shared.v1[ref].flags, flags, 0) == flags)
329+
while (!((flags = *pflags) & GTF_transfer_committed)) {
330+
if (sync_cmpxchg(pflags, flags, 0) == flags)
326331
return 0;
327332
cpu_relax();
328333
}
329334

330335
/* If a transfer is in progress then wait until it is completed. */
331336
while (!(flags & GTF_transfer_completed)) {
332-
flags = gnttab_shared.v1[ref].flags;
337+
flags = *pflags;
333338
cpu_relax();
334339
}
335340

0 commit comments

Comments
 (0)