From patchwork Wed Jun 14 15:32:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenyuan Mi X-Patchwork-Id: 692962 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8953EEB64D8 for ; Wed, 14 Jun 2023 15:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244235AbjFNPcs (ORCPT ); Wed, 14 Jun 2023 11:32:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245118AbjFNPcm (ORCPT ); Wed, 14 Jun 2023 11:32:42 -0400 Received: from zg8tndyumtaxlji0oc4xnzya.icoremail.net (zg8tndyumtaxlji0oc4xnzya.icoremail.net [46.101.248.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE1AD2125; Wed, 14 Jun 2023 08:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fudan.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id; bh=s6WgjVWLfkpxN651qFEtAa7EbFB9eDZZ7A04NJW3HN8=; b=Q DUODjVOcTIOAcKh7GrLfPj8D93IroXBQ23ZFlVTQEl6iRMh0Cogb8m+8kLbWVsEc XSc1M/p0XwjiHwuxUND+VkbddnctkXDuY7gbXwJjkQtbf5tRkbSdU7nv/j2Tfqmy 4Kfbxvmw6ibnqfEE+HUtJU/EiJL6XXAWdwKWM2Hl7U= Received: from ubuntu.localdomain (unknown [10.230.35.76]) by app1 (Coremail) with SMTP id XAUFCgB35T2L3Ylkkl_sAA--.37414S2; Wed, 14 Jun 2023 23:32:28 +0800 (CST) From: Chenyuan Mi To: ilpo.jarvinen@linux.intel.com Cc: andriy.shevchenko@linux.intel.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Chenyuan Mi Subject: [PATCH] serial: 8250_lpss: Fix missing check for return value of pci_get_slot() Date: Wed, 14 Jun 2023 08:32:26 -0700 Message-Id: <20230614153226.117768-1-cymi20@fudan.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: XAUFCgB35T2L3Ylkkl_sAA--.37414S2 X-Coremail-Antispam: 1UD129KBjvdXoW7XF47uFWrJF4DGrWUCr1rZwb_yoWfArgEka 4kAwnxZwnI9F1qkrn3Grn8ArWSk3WjvF1xX3Z2vr98JryDArWUZrWjqa9rXr9rWwsxJF95 Awn7Kr1Sqr1DZjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbskFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IE rcIFxwCY02Avz4vE-syl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2 IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v2 6r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2 IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI42IY6I8E 87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73Uj IFyTuYvjfUOlksUUUUU X-CM-SenderInfo: isqsiiisuqikmt6i3vldqovvfxof0/ Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The pci_get_slot() function may return NULL, which may cause null pointer deference, and most other callsites of pci_get_slot() do Null check. Add Null check for return value of pci_get_slot(). Found by our static analysis tool. Signed-off-by: Chenyuan Mi --- drivers/tty/serial/8250/8250_lpss.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c index 0e43bdfb7459..05af5865ee1b 100644 --- a/drivers/tty/serial/8250/8250_lpss.c +++ b/drivers/tty/serial/8250/8250_lpss.c @@ -137,6 +137,8 @@ static int byt_serial_setup(struct lpss8250 *lpss, struct uart_port *port) } dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0)); + if (!dma_dev) + return -ENODEV; param->dma_dev = &dma_dev->dev; param->m_master = 0;