From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC7361C84D0 for ; Fri, 8 May 2026 00:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778200139; cv=none; b=lhBRcq1f/szNC/FcD0awVnK9mDZML+hNYbUSQs6zXCJgrNOO9JJV8wWItQkmrF0L3vBpQanEmrP1N4jHQu33pM/kK9NO6771YH0hRCEPrVAvAZZirfXS+zi0AziOr0DnmyilOTPMQLU53WQfAtCr0CfBNJwpm4M9DaJNcMZJMsw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778200139; c=relaxed/simple; bh=hiKCvmGqb1uuPjJp0D/nD0i9zzKH3FlhdURMk/RAc6E=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FeL5gYRXNTyv0o3gT1pfMcu0Lqi9iIjt6ixWh0omAb0OmYxzvNQ7QGpXLXn2Y6PTiDghK4nfqRCMVMGALV+u2q8QMEXQo6OegEjWZJ4ZoERUyuWoMoWOLZOWxuP34anZC2XR8DL/CtmSJzK3F3rNT5iKufescc2mdPPr/eo34mQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=icQn8/85; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=DvNtdI3H; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="icQn8/85"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="DvNtdI3H" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 647KwA6g2778219 for ; Fri, 8 May 2026 00:28:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= f+n+hrmRjgNwY691mbAUgor0uxE2JHAX2hCfAk8KTi8=; b=icQn8/85KHbZHbe/ rXtGshr/drVMDgWTXWTjna6dUR2ppXZ8ZoqeIbtErv5dhvZW8gCOkd/U9e9065Yk tbWk0RNm7SJaC7N9bJvKiEkNFdgCFAZCVjMRZlTwquGUBLp17rWvCb3bObLNHf20 ZcaiuH75kUOB03jZ5U1yhFhrmBR4zjSvqgp5hMBdQHPhUxXx0RkQcsyojAXn12JN OAvKGkYvBcysaGa8/ugrg/xLbdquo7jgE7kLJeyI0Q4BGVvLcT5HvZhUfJwlakOf gATIIuWmY209KROEiECGjtEFmMg+JGg4OwQPo/vMhbOjjh3OrPxxxDwoQ/P9X3k/ nwzCxw== Received: from mail-dl1-f70.google.com (mail-dl1-f70.google.com [74.125.82.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4e1285ghd8-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 08 May 2026 00:28:56 +0000 (GMT) Received: by mail-dl1-f70.google.com with SMTP id a92af1059eb24-130a468d5cdso4225206c88.0 for ; Thu, 07 May 2026 17:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778200136; x=1778804936; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=f+n+hrmRjgNwY691mbAUgor0uxE2JHAX2hCfAk8KTi8=; b=DvNtdI3HaKv7L12ql/5F0Q5j6RDfbKpf5x4u44GZsIpsrPi6bo0WA43YShqdqtLlRL DfDfC3+5wMxL/7Tt6Pu066NPwO60cX7yhKmtInfjGAFhPB12FnHYZAUvC6VFORPTQa/c xkP7T0IG3zO6apPdmBeGLRnXgai70JRa6+DEx339Yw+1GA7eyOTIQwF3Gx4fckir1CAR 1oLc6j7CmAXEEXEBPFXJUMFjGeaKueGmR3E6IPOIOGDNOltIPnqpeZ62DO4iZ8rd3ox4 kS9WfIbGxkEEeGykzdtoo/A4/0RvAnUG6Xdq8QTWMmSVyTb3PZy1H4kSlFW26mW/xX4X OrNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778200136; x=1778804936; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f+n+hrmRjgNwY691mbAUgor0uxE2JHAX2hCfAk8KTi8=; b=dE4aGfUtjYTTfcG9WOjZ5/NRIiNlogldq9RN2y4usZiP/unH8tsQ4oozNaX+Av3Ewq VaGbvXsLj7Pi0VOBCjsDOv71LS31O2FY7WGELGsR1b610Y+ly+FcaD3bbmI7eOfClDdH dgGabqldLwJGxabOZ2UAnjLbxSsPQBmsuNcDuErKIXI38HUD5/IF+htcMybQ7rZ8kAU8 1rLsDtzk8HVcSezAPDn6dKhCmFiDS/XJ/dQN57SFq/DLE5ZpW3q6tYTcZ2P+9eoliSdD eXPva56j/n/H4mAf7oyztlWMqpqv+VJXi+GpbFR8xEBj31ZMfBaM/sCDgJhNI1c4eFzZ ZXHQ== X-Forwarded-Encrypted: i=1; AFNElJ/5VudebBmgAXCI+yEF4HLBII8qC4sSJnuLCQNJMGzCY5qS400V8+yJfTK/ACgZooRX+QBpcwNoINErASI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6OhgnozP0thRTOKQ2ftFh+93caoWHCzOgwVbDgaaYVB7nTIKG MOMsWP7GZUHAxFVAdxjnHNfpsap7BCbkgk3ZFTl7RS4vZee+QWb9rjlVv2exMsreWi1/o4aIz+W 7iFbSMFX+9YB2v0fICKkTaTlRWGRtqYGQlZjIHbZ4oP/sEft3gf0AXlNA9cogrQnf4Iw= X-Gm-Gg: AeBDievt0d6K4UUjTMmUf8LxLmNTIzV34t3CH2ApMcpqPPVcmqpPkeYD46vzvQZ2rDN bvft/RrdAZXvqstCaL3DIa8OV1mtQMg1ywxwwg/Oh291JIezyfA0MM+iQIXtcsRir60LNAPAuCc LJkdh2I3FcnLP9z3IN3VRdbmzbCQF25LarFDZCa/RiM57rLw+rNx6ihkMBVrJW+UEdRlxe3rEyo eX8hE24qTqmkUUAqOG8vHtQtK3RRKE1XtaOoegs9pMeWSDEj8WjZ+TF10BEdAcqWfEkJmTuMt2e 6GXIpzlXgmJHECuTjlRhGt1/qioNhfKLS8GULibaPfEz87Wdc2emlvIN1ywMSkZUdYB6E9zG5P4 VGK3MKfYUqCvfGr9ofk6xGFqUtleRUNjtpQ0eM4V16EauwOcOsT9T3jORCBtCDJC1IrfjkFh8Is E/UGE= X-Received: by 2002:a05:7022:3d05:b0:12a:94ab:e20 with SMTP id a92af1059eb24-1318e917636mr5571111c88.20.1778200135791; Thu, 07 May 2026 17:28:55 -0700 (PDT) X-Received: by 2002:a05:7022:3d05:b0:12a:94ab:e20 with SMTP id a92af1059eb24-1318e917636mr5571097c88.20.1778200135037; Thu, 07 May 2026 17:28:55 -0700 (PDT) Received: from [10.71.182.226] (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13278210d40sm154352c88.4.2026.05.07.17.28.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 May 2026 17:28:54 -0700 (PDT) Message-ID: Date: Thu, 7 May 2026 17:28:53 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] usb: dwc3: avoid probe deferral when USB power supply is not available To: Thinh Nguyen Cc: Greg Kroah-Hartman , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "jack.pham@oss.qualcomm.com" , "wesley.cheng@oss.qualcomm.com" References: <20260407232410.4101455-1-elson.serrao@oss.qualcomm.com> <4db536fd-9b20-49ec-a5f3-1fa3f2876c1e@oss.qualcomm.com> Content-Language: en-US From: Elson Serrao In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA4MDAwMiBTYWx0ZWRfXxz5rqE0M3OLJ 7Y90LhK967MP2uLoDEesJ9vilBYQ8V/mQ3YIVN4vyO4l0iRJBt0QwTL0OaLwUjKaZyx7/73S1ig OWU/DW1LZjq3GLvK5twcT14DZYcvhqfaiay83gzgzbbl+7vccDvtdejSe4f62Mo5KclWs7z5m0a UlFVDcXsN6i5pTPRxA27RpQYAMfoyMC1zioD7/RkWM9x4fGeYVakSxlnwFh5O6uH191J7KyZTBx FuOSIvkyfyHvO6V5l8NboDofbgVLRArjdIyLNht40GddPKl4SXXw32VEKYWhKTkVSTyQaBquhWy XqfkDgLGlo7h9C54KoFXvbfBs5qaibQaN0dk+GXmNOl/av9138d/iPi/ZEalo/bL15HlnVCChNC YI9vVKx8G48uJxOtJUI4MNh4f35D38WCwA2vX/kkZGUOg9z0TBQW9tqaOYMn9hYipnhtLVy4RBQ jt3YuWneS0TkTIb+A5g== X-Proofpoint-GUID: KP4zt7qQlTRjvktgsvzLz3LlDs6JeOVa X-Proofpoint-ORIG-GUID: KP4zt7qQlTRjvktgsvzLz3LlDs6JeOVa X-Authority-Analysis: v=2.4 cv=NKblPU6g c=1 sm=1 tr=0 ts=69fd2e48 cx=c_pps a=SvEPeNj+VMjHSW//kvnxuw==:117 a=JYp8KDb2vCoCEuGobkYCKw==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=QjaDh_2JvBKc0s5STn8A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=Kq8ClHjjuc5pcCNDwlU0:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-07_02,2026-05-06_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 suspectscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605080002 On 5/7/2026 4:02 PM, Thinh Nguyen wrote: > On Wed, May 06, 2026, Elson Serrao wrote: >> >> >> On 5/1/2026 5:55 PM, Thinh Nguyen wrote: >>> On Tue, Apr 07, 2026, Elson Serrao wrote: >>>> The dwc3 driver currently defers probe if the USB power supply is not yet >>>> registered. On some platforms, even though charging and power supply >>>> functionality is available during normal operation, there may exist >>>> minimal booting modes (such as recovery or diagnostic environments) where >>>> the relevant USB power supply device is not registered. In such cases, >>>> probe deferral prevents USB gadget operation entirely. >>>> >>>> USB data functionality for basic operation does not inherently depend on >>>> the power supply framework, which is only required for enforcing VBUS >>>> current control. The configured VBUS current limit is typically enforced >>>> through the charger or PMIC power path. When charging functionality is >>>> unavailable, applying a current limit has no practical effect, reducing >>>> the benefit of strict probe-time enforcement in these environments. >>>> >>>> Instead of deferring probe, register a power supply notifier when the >>>> USB power supply is not yet available. Cache the requested VBUS current >>>> limit and apply it once the matching power supply becomes available, as >>>> notified through the registered callback. >>>> >>> >>> This gets a bit cumbersome now that we need to consider some corner >>> cases around the notifier callback. >>> >>>> Signed-off-by: Elson Serrao >>>> --- >>>> drivers/usb/dwc3/core.c | 82 ++++++++++++++++++++++++++++++++------- >>>> drivers/usb/dwc3/core.h | 4 ++ >>>> drivers/usb/dwc3/gadget.c | 10 ++++- >>>> 3 files changed, 80 insertions(+), 16 deletions(-) >>>> >>>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c >>>> index 161a4d58b2ce..20df0b287623 100644 >>>> --- a/drivers/usb/dwc3/core.c >>>> +++ b/drivers/usb/dwc3/core.c >>>> @@ -2167,24 +2167,72 @@ static void dwc3_vbus_draw_work(struct work_struct *work) >>>> if (ret < 0) >>>> dev_dbg(dwc->dev, "Error (%d) setting vbus draw (%d mA)\n", >>>> ret, dwc->current_limit); >>>> + >>>> + /* Unregister the psy notifier now that we have the power_supply reference */ >>>> + if (dwc->psy_nb.notifier_call) { >>> >>> Is it possible for dwc3_core_remove() to happen here? If so, should we >>> do something about it? >>> >> >> Hi Thinh >> >> Thanks for the review. >> >> Yes dwc3_core_remove() could race with this path. >> >> To simplify things, I’m planning to unregister the notifier only >> from dwc3_core_remove(), so we don’t need to handle this case here >> and the notifier lifetime remains tied to the device lifecycle. >> >> Let me know if you’d prefer a different approach. >> > > That's fine to me. Just make sure to return early if the power supply is > registered. > Ack. I will fix this in v2 > > >>>> + >>>> + dwc->usb_psy = power_supply_get_by_name(dwc->usb_psy_name); >>>> + if (!dwc->usb_psy) { >>> >>> Is it possible for the power supply to register here? >>> >> >> The power_supply framework introduces a ~10 ms delay [1] >> before invoking notifiers after registration. So for the race described >> above to occur, our probe would need to stall for more than that >> duration between the initial power_supply_get_by_name() call >> and notifier registration, which seems highly unlikely under normal >> conditions. >> >> That said, there is still a theoretical window where the power >> supply could register in that gap. If you think it's worth being >> defensive here, we could re-check power_supply_get_by_name() after >> registering the notifier and handle the case accordingly. >> >> [1] https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/power/supply/power_supply_core.c?h=v7.1-rc2*n40__;Iw!!A4F2R9G_pg!dUiPW6mibrvsk4uGO4MnGVg3R1zR3EmxxIROrw4N-ytHZq7N9q-V6irNAWrBrolUR2HABsAGSQoMPzGnEGQsvWdhzWzcVHOU$ >> > > For my own sanity, can we have that extra check? Otherwise, every time I > scan through this I would need to recall why it wasn't needed. > Ack. I will fix this in v2 Thanks Elson