From patchwork Wed Aug 7 17:21:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11082521 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61689912 for ; Wed, 7 Aug 2019 17:21:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EE4D2018E for ; Wed, 7 Aug 2019 17:21:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4059B28A44; Wed, 7 Aug 2019 17:21:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D27342018E for ; Wed, 7 Aug 2019 17:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388448AbfHGRV1 (ORCPT ); Wed, 7 Aug 2019 13:21:27 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55756 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730168AbfHGRV1 (ORCPT ); Wed, 7 Aug 2019 13:21:27 -0400 Received: by mail-wm1-f66.google.com with SMTP id f72so790635wmf.5 for ; Wed, 07 Aug 2019 10:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E2EJNQPnOEl3GZNAxpz5JJlhH5o76gr2JP/NdmhEjGs=; b=Slbetn8k4h8b+dLP23JOZzACY2KPtfhEdyy4tIy1t0kM6CLvwNMntuGC8OWdSosCwC Mn1hdHbI42z8YdGqz3QU3H5n2snOQDR/snOwPv52MyekKooNtPIfnm8/xJm1l0R1kd0v GB4Vw1raWpROllTv0w7r/AdyRxKhXb7T0BrhMDejdNdArhaNlj9/4IFqRsPN27rghRaR IroQlGR7jYdWs4YoT8GQbtavA8dOdKl7/jOIXcNFH4NePAZfTYGplEszVQK4o9k/HSoL 65ECmXVSCxDJFQtPd4UuGfmfXGDqliW49oP8V/KGMXudqKR8YfhlR0rej4aMYD4dlDyC uKqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E2EJNQPnOEl3GZNAxpz5JJlhH5o76gr2JP/NdmhEjGs=; b=OFRvWjtKST0d9O207EtJLjmTTZTQrQcuNJp7gULys/9JRsE1B81mmBJgbgk6hklc9s Klf6bmMfo9/Pm+cg06nKAWAdav4GWWAzJ1dZhsIsj0nlhqGtnr2wmwQoq0R3sMd3vLXc BsJkJQKNpf6ydGdVEO6JOaV+8/vfzhF7GqnTYq7sJZoftNHEaGyhi6YZ3HgJ98c010yR Rwupje1HutAB5QsYm7p9WWg366hPMSrfTcHO2olHCk+TTBKprEEWVgrHuRNZSBlcVM1Q D/P2nC3lGEfYLAZPrXmIMmwJUQs7HrbNFJi0RzMq+WNQv0dlmEssroLuRhkcfmMlbPqc XBKw== X-Gm-Message-State: APjAAAXJqH2aJ5KufBY1k2ab5x/okHTVe5uh8SKfWydsik2Tlc0yaPG8 zHAFCZzgCnEVTzo5RaJmerdKuw== X-Google-Smtp-Source: APXvYqzBdRIfE+HrknLNxY/zsTEgRLTff26RF5t3imH7y4D5rR5RbsMu8UTWdbsANsG2R+dUMRYXXg== X-Received: by 2002:a1c:751a:: with SMTP id o26mr920609wmc.13.1565198484766; Wed, 07 Aug 2019 10:21:24 -0700 (PDT) Received: from localhost.localdomain (88-147-66-140.dyn.eolo.it. [88.147.66.140]) by smtp.gmail.com with ESMTPSA id q193sm586773wme.8.2019.08.07.10.21.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 10:21:24 -0700 (PDT) From: Paolo Valente To: Jens Axboe , linux@roeck-us.net Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, linus.walleij@linaro.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, Paolo Valente , Hsin-Yi Wang , Nicolas Boichat , Doug Anderson Subject: [BUGFIX 1/1] block, bfq: handle NULL return value by bfq_init_rq() Date: Wed, 7 Aug 2019 19:21:11 +0200 Message-Id: <20190807172111.4718-2-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190807172111.4718-1-paolo.valente@linaro.org> References: <20190807172111.4718-1-paolo.valente@linaro.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As reported in [1], the call bfq_init_rq(rq) may return NULL in case of OOM (in particular, if rq->elv.icq is NULL because memory allocation failed in failed in ioc_create_icq()). This commit handles this circumstance. [1] https://lkml.org/lkml/2019/7/22/824 Reported-by: Guenter Roeck Reported-by: Hsin-Yi Wang Cc: Hsin-Yi Wang Cc: Nicolas Boichat Cc: Doug Anderson Signed-off-by: Paolo Valente Reviewed-by: Guenter Roeck --- block/bfq-iosched.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 586fcfe227ea..32686300d89b 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2250,9 +2250,14 @@ static void bfq_request_merged(struct request_queue *q, struct request *req, blk_rq_pos(container_of(rb_prev(&req->rb_node), struct request, rb_node))) { struct bfq_queue *bfqq = bfq_init_rq(req); - struct bfq_data *bfqd = bfqq->bfqd; + struct bfq_data *bfqd; struct request *prev, *next_rq; + if (!bfqq) + return; + + bfqd = bfqq->bfqd; + /* Reposition request in its sort_list */ elv_rb_del(&bfqq->sort_list, req); elv_rb_add(&bfqq->sort_list, req); @@ -2299,6 +2304,9 @@ static void bfq_requests_merged(struct request_queue *q, struct request *rq, struct bfq_queue *bfqq = bfq_init_rq(rq), *next_bfqq = bfq_init_rq(next); + if (!bfqq) + return; + /* * If next and rq belong to the same bfq_queue and next is older * than rq, then reposition rq in the fifo (by substituting next @@ -5436,12 +5444,12 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, spin_lock_irq(&bfqd->lock); bfqq = bfq_init_rq(rq); - if (at_head || blk_rq_is_passthrough(rq)) { + if (!bfqq || at_head || blk_rq_is_passthrough(rq)) { if (at_head) list_add(&rq->queuelist, &bfqd->dispatch); else list_add_tail(&rq->queuelist, &bfqd->dispatch); - } else { /* bfqq is assumed to be non null here */ + } else { idle_timer_disabled = __bfq_insert_request(bfqd, rq); /* * Update bfqq, because, if a queue merge has occurred