From patchwork Sat Feb 25 04:11:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: void0red X-Patchwork-Id: 13152027 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 8BC52C6FA8E for ; Sat, 25 Feb 2023 04:12:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229496AbjBYEL6 (ORCPT ); Fri, 24 Feb 2023 23:11:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjBYEL5 (ORCPT ); Fri, 24 Feb 2023 23:11:57 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA006628ED; Fri, 24 Feb 2023 20:11:54 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id c1so1514709plg.4; Fri, 24 Feb 2023 20:11:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8pBEzpVd+snu5F2T0uV1kL07YHenLWu8FxH3t2VC2cg=; b=mYyz2gyWDoRuHWtmyk2M3qcjPcj+6c3fcMQDYYI6zlWiLrqHDbrzc/o6nEE+cIt2Av CZS0dZh4hye5IvjPsO+NUscM/CmxPLA4em51lQ+dZpgCaoKyz08QVqS5c22pMNq32BfC 6VtwVb4Cfmdu5RGIWbSu3PHkeuOxpXKD380Tsj/DTel2i7Lef1AkAxIgKQ4IlQqsUSSt 3ginx2UA+PejVsSf4okhnw19jiSmp9wwmTaZhIfsNS5z8/I+GKg0qrdTya9EaCHBfO/n f8L2pV0R4euYBJfn8712YKdLsAaz0ouW/xjUOXwCAa6STvGQaYFbwKKAH6ydG6jEz64m ad1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8pBEzpVd+snu5F2T0uV1kL07YHenLWu8FxH3t2VC2cg=; b=u5BWmhnABKZpgo4AKNAbg91MHCs3TcFTxtMtv9Qe7OKpllcanz/JyWYpaQdf975J7E ltfqzVK+TfehFTUZjoJ4G/aGlMj531IsbIyPYnFNSqSFN6ZpmFWi3Kcs4lZcsIbTmCM7 l8kTrem0vZ2cGazbvdaEZzSQ+QNh4dr+VgChC9kS3QLYEWf6ukUtTFnL7gIGtW2BHN6c UAGoG23wItf73WN9ZlfDoVCPMajzqt6jlcd4ffQRXpnQxwsDerVkL3Rmdj8siFrkc1vb DpLgdgOTnH3w3d3j6D2IA3moVfePb7tijfJve3QbLIH8t9y7Y7eHmIdDCihsva554wcD xKhA== X-Gm-Message-State: AO0yUKXhMBSdBftPB91orVbNalqHkHVxRpR0qBs3sDZf7EJM6wWx/ugD wMVz2cEX1sVmiDjyQpXIzOUgqXP3ZgF75ztgJi8= X-Google-Smtp-Source: AK7set/glCBFSw0P8vlJ0unVVzMrpzs4wfa6R4gYRagEqe285TdkZwTuzii2Xazd7vwjKIzB2G6n8Q== X-Received: by 2002:a17:90b:224f:b0:234:236f:1a8d with SMTP id hk15-20020a17090b224f00b00234236f1a8dmr21307777pjb.14.1677298314223; Fri, 24 Feb 2023 20:11:54 -0800 (PST) Received: from DESKTOP-HHR6EMI.localdomain ([143.244.50.165]) by smtp.gmail.com with ESMTPSA id q89-20020a17090a756200b0022bfcf5d297sm2268428pjk.9.2023.02.24.20.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 20:11:53 -0800 (PST) From: void0red To: sergei.shtylyov@gmail.com Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, mudongliangabcd@gmail.com, Kang Chen Subject: [PATCH v3 1/2] usb: gadget: udc: add return value check of kzalloc in mv_udc_probe Date: Sat, 25 Feb 2023 12:11:48 +0800 Message-Id: <20230225041149.136-1-void0red@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <17383b82-5e1c-837c-d05f-67a3a024cace@gmail.com> References: <17383b82-5e1c-837c-d05f-67a3a024cace@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Kang Chen Even an 8-byte kzalloc will fail when we don't have enough memory, so we need a nullptr check and do the cleanup when it fails. Reported-by: eriri <1527030098@qq.com> Link: https://bugzilla.kernel.org/show_bug.cgi?id=217081 Signed-off-by: Kang Chen --- v3 -> v2: split the patch into two v2 -> v1: replace kzalloc with devm_kzalloc drivers/usb/gadget/udc/mv_udc_core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c index b397f3a84..6dd6d52de 100644 --- a/drivers/usb/gadget/udc/mv_udc_core.c +++ b/drivers/usb/gadget/udc/mv_udc_core.c @@ -2230,6 +2230,10 @@ static int mv_udc_probe(struct platform_device *pdev) /* allocate a small amount of memory to get valid address */ udc->status_req->req.buf = kzalloc(8, GFP_KERNEL); + if (!udc->status_req->req.buf) { + retval = -ENOMEM; + goto err_destroy_dma; + } udc->status_req->req.dma = DMA_ADDR_INVALID; udc->resume_state = USB_STATE_NOTATTACHED; From patchwork Sat Feb 25 04:11:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: void0red X-Patchwork-Id: 13152028 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 A3B03C7EE2D for ; Sat, 25 Feb 2023 04:12:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbjBYEL7 (ORCPT ); Fri, 24 Feb 2023 23:11:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjBYEL6 (ORCPT ); Fri, 24 Feb 2023 23:11:58 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7066D628F0; Fri, 24 Feb 2023 20:11:57 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id h11-20020a17090a2ecb00b00237c740335cso161909pjs.3; Fri, 24 Feb 2023 20:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m4owclU3ejHWTEBuLrWhmLUuMH4WIISFFiTFNymBI7Y=; b=XkXxmFCYN7J+EoOtMaOQ75oMQcI7DH+npbo5aKGb913jCYH5IDgaZJighknRR9l9MZ RjcCtZubPi7lS+Cvw0o7qun+Qjlcy4FjPk39fggbafNS2y2gyqzefGIkY7she/fSeKJb 5nEXlJBNE1+FhEar5aZwhLRrfesQvMLUj5oUY6LL7T0X39xvzMZIrsZAr/gwbUI4d5hf ypzTLEFTYPNRQqi9+s7Vq7R5GGGKC89oonwEXWWzj86OSF52ZbS3gpLZdFMSdMttD5oI 8QfJRN+VQDVxhrfaOCut+Hs1/Nm7cN+jYFWLUroC8fJA3XsToxsGMZsaYqHPuI63+4XY ngow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m4owclU3ejHWTEBuLrWhmLUuMH4WIISFFiTFNymBI7Y=; b=L6xFKe5uIITBSEmoEKNaUUIbHPceGrAQrqTHY0WQkE6vhY4sUNemhPPu76mwfV5Ldw g4BMa7rhv0W9g17abUJLE2icOCpaa8A1gS8o9oNr1ocoeKLYSiNwVPm/jSLSGYvxfVDB nI5o6c2euz2FS3/gfKZZpwXjTgph81/6rduR/moVp0MNk/3yWfj4u0nVPSvkv6oNlZ1p CVfkpBkFrXBu4iR8scMWqBmZ9I+nG0lZT6GZo3VDPPdGyz7/4LIJlg3mcujNqLXP7GN6 faRzHR6RJzFrHKm1iNhxsJlE1FQKDUV/Nmo60jYwueMF8esZ64+FlKTgz7K/vIkf/QBV x0ew== X-Gm-Message-State: AO0yUKVICz9+OrSI8AqLmn2w1RmDVfAuzTx+3VHWMS5XPAnBHf7NhYY4 broNPeGMdbhISwtN/XokQCs= X-Google-Smtp-Source: AK7set/8B5cAFbTMo3lBGyP+0mWWSByS646Gyb/Crx81sNDpGrdDvkNjGBBEKyHYtwH5lez5mtxgow== X-Received: by 2002:a17:90b:38ce:b0:236:704d:ab8c with SMTP id nn14-20020a17090b38ce00b00236704dab8cmr19553076pjb.26.1677298316923; Fri, 24 Feb 2023 20:11:56 -0800 (PST) Received: from DESKTOP-HHR6EMI.localdomain ([143.244.50.165]) by smtp.gmail.com with ESMTPSA id q89-20020a17090a756200b0022bfcf5d297sm2268428pjk.9.2023.02.24.20.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 20:11:56 -0800 (PST) From: void0red To: sergei.shtylyov@gmail.com Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, mudongliangabcd@gmail.com, Kang Chen Subject: [PATCH v3 2/2] usb: gadget: udc: replace kzalloc with devm_kzalloc in mv_udc_probe Date: Sat, 25 Feb 2023 12:11:49 +0800 Message-Id: <20230225041149.136-2-void0red@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230225041149.136-1-void0red@gmail.com> References: <17383b82-5e1c-837c-d05f-67a3a024cace@gmail.com> <20230225041149.136-1-void0red@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Kang Chen This driver uses the unified memory management api, so replace kzalloc with devm_kzalloc to avoid a memory leak. Reported-by: Dongliang Mu Link: https://lore.kernel.org/all/CAD-N9QX5i5toj8cs7DxBjYWtRGf3ZRnfTAf809sFW6iX0Ktfmw@mail.gmail.com Signed-off-by: Kang Chen --- v3 -> v2: split the patch into two v2 -> v1: replace kzalloc with devm_kzalloc drivers/usb/gadget/udc/mv_udc_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c index 6dd6d52de..08474c08d 100644 --- a/drivers/usb/gadget/udc/mv_udc_core.c +++ b/drivers/usb/gadget/udc/mv_udc_core.c @@ -2229,7 +2229,7 @@ static int mv_udc_probe(struct platform_device *pdev) INIT_LIST_HEAD(&udc->status_req->queue); /* allocate a small amount of memory to get valid address */ - udc->status_req->req.buf = kzalloc(8, GFP_KERNEL); + udc->status_req->req.buf = devm_kzalloc(&pdev->dev, 8, GFP_KERNEL); if (!udc->status_req->req.buf) { retval = -ENOMEM; goto err_destroy_dma;