Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp353669pxb; Wed, 14 Apr 2021 17:36:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7C6SCRfzqiGL0105X2cBr/gtUVVK/rJCiHVb8IcKfT/AMeb24PaFYjQ+c2tsRtUnfiTcv X-Received: by 2002:aa7:8e81:0:b029:250:5c33:b4ea with SMTP id a1-20020aa78e810000b02902505c33b4eamr752598pfr.54.1618446988638; Wed, 14 Apr 2021 17:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618446988; cv=none; d=google.com; s=arc-20160816; b=rGaxkAKPK7XtLyUPa8pzVC68tQMzGzX0g8Bpgta8RXYv0rZxhKi/rnW14VHrcUNvU4 Qkt1sqlNJzl1oJeE6wsyEHGNI/FU0HyIrDJWiXWDJIlHHs4KbgEWuWTMB+9DAZypSt6Q 6Ylt0SutYSx6/8ccvaMgg+R+00i3tyUqIf4/4EllEj+I7zTQrKndAf7UycZjvj7n6t/d brCdAdHNN/Dl6rDrCum5bhXLI5WgmPTdNfUn96nCdiq2RCX3v3fKi6UbJWdqn/3MgSc5 3gOEkrWx5pjSk1hwGPxQxMPm07mbRhLvNTi7m8LED1pg6itU95KdDO0dyt9RmibhhJHI 5GVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=wVq5foHH9Gaaq6153ho9rL+iG2c35b1wovpXdy6r7uk=; b=z3vd5jI7RP7Dwax63tL4Nz9eX8sfV1GqtVgV52tOLDyOsqWh5IoN48f8nsfzb2h+FH IqolK0vQPfqruCBSCOMQPUeBYWn/thoh9l4zsiZ6Ng/UBQb8uJiPEIHlHSApaRLKdzda VhodX8bhCsrtZJbDEq52RNb4XkS2yT7W2WD5srGV23VHtUXAsrZFTZDQvzvPKbTgekV4 UyYj3GkcqQrLOW3QrttQWrwWYzy78w2EhR3bygeh++XE45I16UE5t+XcafLzdTHBEv7S cvxfKEw/S42jg9YgkiiRpVweBHzQUcy9qNe281RuC4wsHhhUtYrsFS6zBQn/WbJhlL6h O2tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QMUyXw0i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j23si1252360pji.27.2021.04.14.17.36.15; Wed, 14 Apr 2021 17:36:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QMUyXw0i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351925AbhDNQuJ (ORCPT + 99 others); Wed, 14 Apr 2021 12:50:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:45624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232143AbhDNQuG (ORCPT ); Wed, 14 Apr 2021 12:50:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A679561153; Wed, 14 Apr 2021 16:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618418985; bh=sWQ71+khW/HhXEH6hXNiMZxDq1vYrXn/LOWzn6c44Bg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=QMUyXw0imrkvaPO1DWlSoQPOurzaRmc1x1bEpx2J2ASyKkNIRZnHyThxy/B/lhFdZ WU3Gt3PTy3qprvS11oWrVbrpTm6l8VGR/c6WygHAXfQuBI9fOqp17Nv4P7+kHpSvMr A16Bh3y/EoduKIVAZDoqth0DJM9MYRmcuw00wMxwpM5fgRRjjzATgPaCHq1euVbhqA ibH3KIrG/E7ICcMmKJbTtDhy20hsvB7Q/i2hI15w9oGaQ4W+OaUXYwe0HoGw2UAM2D R8FK2q3K5tKKScXXv+taCmhIc6umUcgvIkkeDJeE5/s03heWQcs6QKLgYM2WOPUtSk Exdf3oa672aIQ== Subject: Re: [PATCH 1/3] mmc: sdhci-s3c: fix possible NULL pointer dereference when probed via platform To: Krzysztof Kozlowski , Ben Dooks , Jaehoon Chung , Adrian Hunter , Ulf Hansson , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski References: <20210414151242.102313-1-krzysztof.kozlowski@canonical.com> From: Sylwester Nawrocki Message-ID: <74059494-3610-c24e-7d09-b89106c0a396@kernel.org> Date: Wed, 14 Apr 2021 18:49:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14.04.2021 17:25, Krzysztof Kozlowski wrote: > On 14/04/2021 17:12, Krzysztof Kozlowski wrote: >> The driver can be matched by legacy platform way or OF-device matching. >> In the first case, of_match_node() can return NULL, which immediately >> would be dereferenced to get the match data. >> >> Addresses-Coverity: Dereference null return value >> Fixes: cd1b00eb24b0 ("mmc: sdhci-s3c: Add device tree support") >> Signed-off-by: Krzysztof Kozlowski >> -#ifdef CONFIG_OF >> -static const struct of_device_id sdhci_s3c_dt_match[]; >> -#endif >> - >> static inline struct sdhci_s3c_drv_data *sdhci_s3c_get_driver_data( >> struct platform_device *pdev) >> { >> #ifdef CONFIG_OF >> - if (pdev->dev.of_node) { >> - const struct of_device_id *match; >> - match = of_match_node(sdhci_s3c_dt_match, pdev->dev.of_node); > > Now I have second thoughts whether NULL pointer can actually happen. If > device is matched via platform/board files, maybe the pdev->dev.of_node > will be NULL thus skipping this branch? > > Could there be a case where device is matched via platform_device_id() > (which has different name than compatible!) and (pdev->dev.of_node) is > still assigned? Maybe in case of out of tree DTS? That seems unlikely, the platform device would need to be initialized via board file and then its of_node assigned somehow. It doesn't make much sense to me. We either use board file or dtb to instantiate devices. > Anyway, the patch makes the code simpler/smaller, so I still think it is > reasonable. Just the severity of issue is questionable... Yes, the patch looks good. Similar cleanups are already done in most of the s3c/s5p/exynos drivers. -- Thanks, Sylwester