Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp3817980rwp; Sat, 15 Jul 2023 09:59:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlFtRKScmKome+o7/UQzQZSn6xXfrZSLu/YDngGm4DV6Ow2z05dEp3dAZ85tXPON3/mp8GAh X-Received: by 2002:a05:6a00:130d:b0:678:5629:fd43 with SMTP id j13-20020a056a00130d00b006785629fd43mr8144254pfu.9.1689440367640; Sat, 15 Jul 2023 09:59:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689440367; cv=none; d=google.com; s=arc-20160816; b=RQuEqVnC0XTkqVhZilzT4M2Q9Av/BZMB2ZjnxquqURt318K+9NuZaDmk3C8ixditMI 8FlTwBXc30zssddN13+UssmWA9O/uac5RsonqOqnl/ePMYF8+kGniucnpgAheV4BW8WS MpW2OH82q/JI7Dlz4jCCbWcyIFcZzqpT/nC6kE4YE+Uuj4VSUR8Ue8Maeh1Q7DsaPAoO ix2IkivlRJeGA2tXBCbFp38RwndmAOtdtJ8uFzI9pICwD8sibNCDUQSXarCB4UgYotyu BfgukcWPVPIFKHM9h297F33Qdn9hWr7L2i0x7uMskzuRg5pQ03cj0Jqw44FU7aldVj0w z17A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=oF5L5fdsheXdW4FCgpI8nwilAf+nvvySGrScnnOzsHs=; fh=E4VHYYzdvkMHKlypVM4HRu/KhDxpw8ahEjhJrWLV7RE=; b=FSKJvF+6VzaM6HXQUA2QivnFScE1BOsIU2CjNtoSglEmxM7DjYroUzxcvRJMa1/H3z eFt72XGYOF2MF0ytP7TxiRroQ5jB2W0d4gBRFoEWddiGh3JnCXVZl9qWDSMZvQFpPYqQ LCOgEvnc90W0SwwGIj1AIjV1aayS0JpScAc8BTUFU5ALZb4SgdU4b5yjczl8fPV5mVIj 8y2dcZ65qkPLQGJH37Atg5GbCrvybd9Fanvffd7r1gBAb0YSA829NAhdLzYcewMWm+AD hA/SSgXJByNT54ykj5Wcm9iLZafdcO8X9dbeA/p/3UkGeIt6Jkrwbzls5TcA19Aq37UJ YidQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=cJbpiW1P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p27-20020a056a000a1b00b006765f19e479si3168632pfh.132.2023.07.15.09.59.15; Sat, 15 Jul 2023 09:59:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=cJbpiW1P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229808AbjGOQiX (ORCPT + 99 others); Sat, 15 Jul 2023 12:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjGOQiW (ORCPT ); Sat, 15 Jul 2023 12:38:22 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CC27E43 for ; Sat, 15 Jul 2023 09:38:21 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-263315da33cso598715a91.0 for ; Sat, 15 Jul 2023 09:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689439101; x=1690043901; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=oF5L5fdsheXdW4FCgpI8nwilAf+nvvySGrScnnOzsHs=; b=cJbpiW1PjvUlB+7JHcMUH2p7CHnCn3wa8Fc11TSAnOMvPS4XJLP0FbTLmyVG/K1HON H17k2Dh1V2n+k15uE88MxNPFGCTa50pZeC/9HcT0xYeDTY5Or3/UhXZ+7PMvzIjzhFzn LCgF0brRckx9uXixYPGd3YETOSfvaAywLwsJEqNYrv4oR9DDu0ef6MZtY6V2wpxdi8d0 nVZNMlsRdXj5IjV0Q8VnSgeRurXMX7vLyzfSVeXrdMVsAJVT+FCfP+gieObrQz3quaFj bYiyn8kJo7M0glTaI+5jKLmF07kQ7zSyl5UoGdMUeDNxrlNJhPwRpWghS6r+doG00dnQ Pf5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689439101; x=1690043901; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oF5L5fdsheXdW4FCgpI8nwilAf+nvvySGrScnnOzsHs=; b=WeOJLHfpGh82pYICD2wEeohBrdW9Iy4WhGSrL+O+uZKmFRYgM9RoY3KgMHH1DXfvrH Ob5BYM3GdLeTCtBTw3t4lu0s6Uh9TKA1BFp6XJa1MK/xq8I9wPJg0pTV/5wPwmTr2id1 dHmi5VnJM0t3pfasZ2nYyt3P+/DKRqwbq5ZPY2DiOoeY09ZKeZBVqbi/tjZ0W/zffCPc L6JqlhXVC8kWTSQwwPizkIwRotBbSPicW/YlHBxqss8sSYZ1D1Vn0U8G2jxeaNQXyJLe tYkTSAqyAjJjc956ZghPO/GgVdi3rzOM05jhlitLb0cTtJ8MTwGdJ/e72wxWkvPiQuoM 3gZA== X-Gm-Message-State: ABy/qLYEuG/Dr97yOKgpovlIMg6CIDOB15gFqetNaVtI8804C4wQygoM iSbDzvvB6CoUug4w3Q300HBeKA2YHol1wwwowTlnwQSrTY4= X-Received: by 2002:a17:90a:4a91:b0:258:9621:913f with SMTP id f17-20020a17090a4a9100b002589621913fmr7622607pjh.3.1689439100686; Sat, 15 Jul 2023 09:38:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fabio Estevam Date: Sat, 15 Jul 2023 13:38:09 -0300 Message-ID: Subject: Re: [PATCH] bus: imx-weim: fix to avoid potential NULL pointer dereference To: Zhang Shurong Cc: shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Zhang, On Sat, Jul 15, 2023 at 12:21=E2=80=AFPM Zhang Shurong wrote: > > of_match_device() may fail and returns a NULL pointer. > > Fix this by checking the return value of of_match_device. > > Fixes: 3f98b6baad63 ("drivers: bus: imx-weim: Add support for i.MX1/21/25= /27/31/35/50/51/53") > Signed-off-by: Zhang Shurong > --- > drivers/bus/imx-weim.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c > index 52a5d0447390..65402bb60c18 100644 > --- a/drivers/bus/imx-weim.c > +++ b/drivers/bus/imx-weim.c > @@ -202,15 +202,19 @@ static int weim_timing_setup(struct device *dev, st= ruct device_node *np, > > static int weim_parse_dt(struct platform_device *pdev) > { > - const struct of_device_id *of_id =3D of_match_device(weim_id_tabl= e, > - &pdev->dev); > - const struct imx_weim_devtype *devtype =3D of_id->data; > + const struct of_device_id *of_id; > + const struct imx_weim_devtype *devtype; > int ret =3D 0, have_child =3D 0; > struct device_node *child; > struct weim_priv *priv; > void __iomem *base; > u32 reg; > > + of_id =3D of_match_device(weim_id_table, &pdev->dev); > + if (!of_id) > + return -EINVAL; If there is no match the driver will not probe in the first place. I don't think this check is needed.