Re: [PATCH v2 4/5] drivers/misc/sgi-gru: fix dereference of ERR_PTR

From: Dimitri Sivanich
Date: Thu Sep 03 2015 - 14:46:00 EST


On Thu, Sep 03, 2015 at 08:20:50PM +0530, Sudip Mukherjee wrote:
> gru_alloc_gts() can fail and it can return ERR_PTR(errvalue). We should
> not dereference it if it has returned error. And incase it has returned
> error then wait for some time and try again.
>
> Signed-off-by: Sudip Mukherjee <sudip@xxxxxxxxxxxxxxx>
> ---
>
> v2: on error retry after msleep(1).
> v1: returned error.
>
> drivers/misc/sgi-gru/grukservices.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/misc/sgi-gru/grukservices.c b/drivers/misc/sgi-gru/grukservices.c
> index 490b79a..d64f2a0 100644
> --- a/drivers/misc/sgi-gru/grukservices.c
> +++ b/drivers/misc/sgi-gru/grukservices.c
> @@ -160,7 +160,14 @@ static void gru_load_kernel_context(struct gru_blade_state *bs, int blade_id)
> down_write(&bs->bs_kgts_sema);
>
> if (!bs->bs_kgts) {
> - bs->bs_kgts = gru_alloc_gts(NULL, 0, 0, 0, 0, 0);
> + do {
> + bs->bs_kgts = gru_alloc_gts(NULL, 0, 0, 0, 0, 0);
> + if (IS_ERR(bs->bs_kgts)) {
> + msleep(1);
> + continue;
> + }
> + break;
> + } while (true);

How about this way (for a little more compactness)?

+ do {
+ bs->bs_kgts = gru_alloc_gts(NULL, 0, 0, 0, 0, 0);
+ if (!IS_ERR(bs->bs_kgts))
+ break;
+ msleep(1)
+ } while (true);
> bs->bs_kgts->ts_user_blade_id = blade_id;
> }
> kgts = bs->bs_kgts;
> --
> 1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/