Skip to content

Commit 6fdf72c

Browse files
NickJackolsonVasily Gorbik
authored andcommitted
s390/sthyi: Move diag operations
Move diag204 related operations to their own functions for better error handling and better readability. Acked-by: Heiko Carstens <[email protected]> Reviewed-by: Tobias Huschle <[email protected]> Signed-off-by: Mete Durlu <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent f449395 commit 6fdf72c

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

arch/s390/kernel/sthyi.c

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,37 @@ static struct diag204_x_part_block *lpar_cpu_inf(struct lpar_cpu_inf *part_inf,
300300
return (struct diag204_x_part_block *)&block->cpus[i];
301301
}
302302

303+
static void *diag204_get_data(void)
304+
{
305+
unsigned long subcode;
306+
void *diag204_buf;
307+
int pages, rc;
308+
309+
subcode = DIAG204_SUBC_RSI;
310+
subcode |= DIAG204_INFO_EXT;
311+
pages = diag204(subcode, 0, NULL);
312+
if (pages < 0)
313+
return ERR_PTR(pages);
314+
if (pages == 0)
315+
return ERR_PTR(-ENODATA);
316+
diag204_buf = __vmalloc_node(array_size(pages, PAGE_SIZE),
317+
PAGE_SIZE, GFP_KERNEL, NUMA_NO_NODE,
318+
__builtin_return_address(0));
319+
if (!diag204_buf)
320+
return ERR_PTR(-ENOMEM);
321+
subcode = DIAG204_SUBC_STIB7;
322+
subcode |= DIAG204_INFO_EXT;
323+
rc = diag204(subcode, pages, diag204_buf);
324+
if (rc < 0) {
325+
vfree(diag204_buf);
326+
return ERR_PTR(rc);
327+
}
328+
return diag204_buf;
329+
}
330+
303331
static void fill_diag(struct sthyi_sctns *sctns)
304332
{
305-
int i, r, pages;
333+
int i;
306334
bool this_lpar;
307335
void *diag204_buf;
308336
void *diag224_buf = NULL;
@@ -312,22 +340,10 @@ static void fill_diag(struct sthyi_sctns *sctns)
312340
struct lpar_cpu_inf lpar_inf = {};
313341

314342
/* Errors are handled through the validity bits in the response. */
315-
pages = diag204((unsigned long)DIAG204_SUBC_RSI |
316-
(unsigned long)DIAG204_INFO_EXT, 0, NULL);
317-
if (pages <= 0)
343+
diag204_buf = diag204_get_data();
344+
if (IS_ERR(diag204_buf))
318345
return;
319346

320-
diag204_buf = __vmalloc_node(array_size(pages, PAGE_SIZE),
321-
PAGE_SIZE, GFP_KERNEL, NUMA_NO_NODE,
322-
__builtin_return_address(0));
323-
if (!diag204_buf)
324-
return;
325-
326-
r = diag204((unsigned long)DIAG204_SUBC_STIB7 |
327-
(unsigned long)DIAG204_INFO_EXT, pages, diag204_buf);
328-
if (r < 0)
329-
goto out;
330-
331347
diag224_buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
332348
if (!diag224_buf || diag224(diag224_buf))
333349
goto out;

0 commit comments

Comments
 (0)