From patchwork Wed Apr 22 14:43:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11504027 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 440571575 for ; Wed, 22 Apr 2020 14:44:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BD3C2082E for ; Wed, 22 Apr 2020 14:44:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="b9QvVsiB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbgDVOoA (ORCPT ); Wed, 22 Apr 2020 10:44:00 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:36586 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726066AbgDVOoA (ORCPT ); Wed, 22 Apr 2020 10:44:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587566639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=X1m+KyBEjIchG4rjXeDIQpyNNPLZZU2rr+C9a+kRM8A=; b=b9QvVsiBLF80Xky4vaQMcDjgf70kqbMdvxeuQaTf8JqLc9DobK3JcvJ4YC8fVRcTPvyySW 0SMCsQOLDjh2sRSm5B6XRTVLbqj3hdAXxQxEy293kvFxBINmBxZmxeA6h4OiIn4s+2C6dV KRosuwzfdpvms6YlMvgqBHlM5xemyso= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-107-hpjANUAGM--r1Tc4Vd1P2A-1; Wed, 22 Apr 2020 10:43:50 -0400 X-MC-Unique: hpjANUAGM--r1Tc4Vd1P2A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22DA6801504; Wed, 22 Apr 2020 14:43:49 +0000 (UTC) Received: from x1.localdomain.com (ovpn-113-5.ams2.redhat.com [10.36.113.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF411600DE; Wed, 22 Apr 2020 14:43:47 +0000 (UTC) From: Hans de Goede To: Greg Kroah-Hartman , Heikki Krogerus Cc: Hans de Goede , linux-usb@vger.kernel.org, Naoki Kiryu , stable@vger.kernel.org Subject: [PATCH] usb: typec: altmode: Fix typec_altmode_get_partner sometimes returning an invalid pointer Date: Wed, 22 Apr 2020 16:43:45 +0200 Message-Id: <20200422144345.43262-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Naoki Kiryu Before this commit, typec_altmode_get_partner would return a const struct typec_altmode * pointing to address 0x08 when to_altmode(adev)->partner was NULL. Add a check for to_altmode(adev)->partner being NULL to fix this. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=206365 BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1785972 Fixes: 5f54a85db5df ("usb: typec: Make sure an alt mode exist before getting its partner") Cc: stable@vger.kernel.org Signed-off-by: Naoki Kiryu Signed-off-by: Hans de Goede Acked-by: Heikki Krogerus --- drivers/usb/typec/bus.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c index c823122f9cb7..e8ddb81cb6df 100644 --- a/drivers/usb/typec/bus.c +++ b/drivers/usb/typec/bus.c @@ -198,7 +198,10 @@ EXPORT_SYMBOL_GPL(typec_altmode_vdm); const struct typec_altmode * typec_altmode_get_partner(struct typec_altmode *adev) { - return adev ? &to_altmode(adev)->partner->adev : NULL; + if (!adev || !to_altmode(adev)->partner) + return NULL; + + return &to_altmode(adev)->partner->adev; } EXPORT_SYMBOL_GPL(typec_altmode_get_partner);