From patchwork Mon Apr 17 19:50:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Korotkov X-Patchwork-Id: 675565 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 F1B62C77B72 for ; Mon, 17 Apr 2023 19:50:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbjDQTuq (ORCPT ); Mon, 17 Apr 2023 15:50:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbjDQTup (ORCPT ); Mon, 17 Apr 2023 15:50:45 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BB974224; Mon, 17 Apr 2023 12:50:43 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4ec816d64afso7885497e87.1; Mon, 17 Apr 2023 12:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681761042; x=1684353042; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xmTAefnrkJJwhbxgaXaqi9Y6GqFc0zYnwZAZbshHD/8=; b=JFK28mWoki10heM23/ZLjso0gjyA2DOgOKQ0DSKwROwtAKBK3ZR+z1EGVEvub91jiL +BPP35l18LlHRRGdNjw1hzvZm7eGrODuQ0wsZaZg0d8qtcSMx92Wwm7r2pr4BpwRP39K 88rskyfeG24N9Rs0cAN9nK3/adZ1THawlcsn0+xzBvBzsuIL+6YVlfNz+vkojbAduiIw exGBVYS5/GmG9n1VEpw2pFs+cXwIREJ/LPbMHoZOz8VMfzY6W3pApu9asFdrn4we3hYd cJ4HtMzZMuNu3Gv0Xu7aLRwu2vmzdn6LrsogELaqPhIM/yd9QHukDUl5pLbFnCh/Ezih 5F8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681761042; x=1684353042; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xmTAefnrkJJwhbxgaXaqi9Y6GqFc0zYnwZAZbshHD/8=; b=Rgzh4L+EnIVtEGFrGaGACe96oTyU5SGig+BaLDeLPimEgNPiN0Erb4KN1zv4KThywD /H4bz0gBA7cYutuzgSIc4fwpFbieQZFSyPW4bpgyLPclP0WZZnI8HVx5OYArTeIR7Q0y 91O/gR0Yz5xX1r4Mwdf9a8CSczotPBj4QsDm7Zt4DlXXJTEBlT0ehgRrumXc5QVgBpWv 3hTbFwysOHDR72SdKBATqHGm9O/CZV2WdkQnjVXA58gkpem3HKBNo5HYhctZk2daU1q5 OoDQJIDCbqijGxT1ouaXaBmj2q/HWbUl0nlzXH69tIDAmSwol/bmU4VoLu/YXl6UPt2D vk0A== X-Gm-Message-State: AAQBX9dAjVDMyevj3/H5cBS9KAoyICWbLIuCiUQcA8j0DWTrdsB5PxXH TQp0V5Rb5IFzX/6hlvO4y/M= X-Google-Smtp-Source: AKy350ZJZKuI6qvz2aeUHt+Tlj30SiXRPuVZtIwznLEmrM3i6Xip3k9wdJlSNGMWEcb6kAGplYMGqw== X-Received: by 2002:a05:6512:3d07:b0:4ed:b86b:9cc9 with SMTP id d7-20020a0565123d0700b004edb86b9cc9mr2219540lfv.28.1681761041646; Mon, 17 Apr 2023 12:50:41 -0700 (PDT) Received: from mkor.. (89-109-50-74.dynamic.mts-nn.ru. [89.109.50.74]) by smtp.gmail.com with ESMTPSA id v6-20020a2e9246000000b0029ee7bc0114sm2248537ljg.64.2023.04.17.12.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 12:50:41 -0700 (PDT) From: Maxim Korotkov To: Heikki Krogerus Cc: Maxim Korotkov , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH] usb: typec: fix potential NULL dereference Date: Mon, 17 Apr 2023 22:50:03 +0300 Message-Id: <20230417195003.19504-1-korotkov.maxim.s@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The pointer 'adev' was being dereferenced before being checked for NULL in the 'type_alt mode_enter()' and 'type_alt mode_exit()' functions. Although this is a hypothetical issue, it's better to move the pointer assignment after the NULL check to avoid any potential problems. Found by Linux Verification Center with Svace static analyzer. Fixes: 8a37d87d72f0 ("usb: typec: Bus type for alternate modes") Signed-off-by: Maxim Korotkov --- drivers/usb/typec/bus.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c index 098f0efaa58d..ae0aca8f33db 100644 --- a/drivers/usb/typec/bus.c +++ b/drivers/usb/typec/bus.c @@ -125,13 +125,16 @@ EXPORT_SYMBOL_GPL(typec_altmode_notify); */ int typec_altmode_enter(struct typec_altmode *adev, u32 *vdo) { - struct altmode *partner = to_altmode(adev)->partner; - struct typec_altmode *pdev = &partner->adev; + struct altmode *partner; + struct typec_altmode *pdev; int ret; if (!adev || adev->active) return 0; + partner = to_altmode(adev)->partner; + pdev = &partner->adev; + if (!pdev->ops || !pdev->ops->enter) return -EOPNOTSUPP; @@ -156,13 +159,15 @@ EXPORT_SYMBOL_GPL(typec_altmode_enter); */ int typec_altmode_exit(struct typec_altmode *adev) { - struct altmode *partner = to_altmode(adev)->partner; - struct typec_altmode *pdev = &partner->adev; + struct altmode *partner; + struct typec_altmode *pdev; int ret; if (!adev || !adev->active) return 0; + partner = to_altmode(adev)->partner; + pdev = &partner->adev; if (!pdev->ops || !pdev->ops->exit) return -EOPNOTSUPP;