Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4215386ybi; Tue, 11 Jun 2019 02:57:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHZyZBKrzkmcReM40f242CukmhYWWQHRoRxr8nLvXgaE2q5EcbsNHbEsH1u2BOVN2W0gWY X-Received: by 2002:aa7:8007:: with SMTP id j7mr15252827pfi.154.1560247072443; Tue, 11 Jun 2019 02:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560247072; cv=none; d=google.com; s=arc-20160816; b=Ep4paKdmnRvOVIJ0tBxjrdvVnby7AO/xu1BtZeR+WZ6odPUqVgR7dpmYyYK8lLqcHr b7aeFo6WWfasef3vpty/PzwEosI2kmR8Vs6xiKDzOintluXc4xGcnmZ+xreCai00fLRF iUWPKM3Atj/uJWxTsOfMOGMD+XhevUWvPB6zx3Q31JYLjgSxhs6xuZFsxSVxkWw4ZGnw ZWjElOJcbjAigFo27t4h64Hcewl6Q+UAoIWVo1ThCbkLMRAh+Kh58RISLh5gHr64v2gy AC0dUCVRt6InatL9Pra77UzbMaCrdzgBjKVDm862/h8N3Ip6X0KOoS65J7BEBuJ3NahT VyJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:openpgp:from:references:cc:to :subject; bh=+HYFXEN/MDITEhYymQKpa1JwyaS+oWXEUzdnccjv9uc=; b=DaG3yKLbktiIte2tv2F/jpw7PAJCyfyS/hJwwxXaE6N0fS3hQN1uYbSjmDzdh4Rkg9 vjszrD3HMsU5XCGt8/CmCwEQIYVpWuzwI+80I2Hz1jFi8Kmbz/XrvfjcCQEOUGXM7tdr WiUO5NMGDRNwk/E1NJ6VUi8e2F/KiCn2MxV4TMNkqyEk3y/jXr/j4F5kG3ax9IWbecVZ DJG1wnrZKky4opgVGYcBR9nJSm/0ChDmdkrIcwJNojmgxYuY/94dzv5ba9gShgAzkPyP rETLWBj7cgCAAIcna2vA8ydCPfJFyp5Qi9URO+ai3nsWFZeGD9hl0GqPJGs0MH2xQ6/y ZEmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8si6129788pls.118.2019.06.11.02.57.37; Tue, 11 Jun 2019 02:57:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391337AbfFKJyT (ORCPT + 99 others); Tue, 11 Jun 2019 05:54:19 -0400 Received: from foss.arm.com ([217.140.110.172]:56928 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391206AbfFKJyS (ORCPT ); Tue, 11 Jun 2019 05:54:18 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D0670337; Tue, 11 Jun 2019 02:54:17 -0700 (PDT) Received: from [10.1.197.61] (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7E5CF3F73C; Tue, 11 Jun 2019 02:55:59 -0700 (PDT) Subject: Re: [PATCH] knav_qmss_queue: fix a missing-check bug in knav_pool_create() To: Gen Zhang , ssantosh@kernel.org, olof@lixom.net Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20190530033949.GA8895@zhanggen-UX430UQ> <20190611093744.GA9783@ubuntu> From: Marc Zyngier Openpgp: preference=signencrypt Autocrypt: addr=marc.zyngier@arm.com; prefer-encrypt=mutual; keydata= mQINBE6Jf0UBEADLCxpix34Ch3kQKA9SNlVQroj9aHAEzzl0+V8jrvT9a9GkK+FjBOIQz4KE g+3p+lqgJH4NfwPm9H5I5e3wa+Scz9wAqWLTT772Rqb6hf6kx0kKd0P2jGv79qXSmwru28vJ t9NNsmIhEYwS5eTfCbsZZDCnR31J6qxozsDHpCGLHlYym/VbC199Uq/pN5gH+5JHZyhyZiNW ozUCjMqC4eNW42nYVKZQfbj/k4W9xFfudFaFEhAf/Vb1r6F05eBP1uopuzNkAN7vqS8XcgQH qXI357YC4ToCbmqLue4HK9+2mtf7MTdHZYGZ939OfTlOGuxFW+bhtPQzsHiW7eNe0ew0+LaL 3wdNzT5abPBscqXWVGsZWCAzBmrZato+Pd2bSCDPLInZV0j+rjt7MWiSxEAEowue3IcZA++7 ifTDIscQdpeKT8hcL+9eHLgoSDH62SlubO/y8bB1hV8JjLW/jQpLnae0oz25h39ij4ijcp8N t5slf5DNRi1NLz5+iaaLg4gaM3ywVK2VEKdBTg+JTg3dfrb3DH7ctTQquyKun9IVY8AsxMc6 lxl4HxrpLX7HgF10685GG5fFla7R1RUnW5svgQhz6YVU33yJjk5lIIrrxKI/wLlhn066mtu1 DoD9TEAjwOmpa6ofV6rHeBPehUwMZEsLqlKfLsl0PpsJwov8TQARAQABtCNNYXJjIFp5bmdp ZXIgPG1hcmMuenluZ2llckBhcm0uY29tPokCTwQTAQIAOQIbAwYLCQgHAwIGFQgCCQoLBBYC AwECHgECF4AWIQSf1RxT4LVjGP2VnD0j0NC60T16QwUCXO+WxgAKCRAj0NC60T16QzfuEACd oPsSJdUg3nm61VKq86Pp0mfCC5IVyD/vTDw3jDErsmtT7t8mMVgidSJe9cMEudLO5xske/mY sC7ZZ4GFNRRsFs3wY5g+kg4yk2UY6q18HXRQJwzWCug2bkJPUxbh71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W3BuZF1o2+y+eVqkPZj0 mzfChEsiNIAY6KPDMVdInILYdTUAC5H26jj9CR4itBUcjE/tMll0n2wYRZ14Y/PM+UosfAhf YfN9t2096M9JebksnTbqp20keDMEBvc3KBkboEfoQLU08NDo7ncReitdLW2xICCnlkNIUQGS WlFVPcTQ2sMAEQEAAYkCHwQYAQIACQUCTol/RQIbDAAKCRAj0NC60T16QwsFD/9T4y30O0Wn MwIgcU8T2c2WwKbvmPbaU2LDqZebHdxQDemX65EZCv/NALmKdA22MVSbAaQeqsDD5KYbmCyC czilJ1i+tpZoJY5kJALHWWloI6Uyi2s1zAwlMktAZzgGMnI55Ifn0dAOK0p8oy7/KNGHNPwJ eHKzpHSRgysQ3S1t7VwU4mTFJtXQaBFMMXg8rItP5GdygrFB7yUbG6TnrXhpGkFBrQs9p+SK vCqRS3Gw+dquQ9QR+QGWciEBHwuSad5gu7QC9taN8kJQfup+nJL8VGtAKgGr1AgRx/a/V/QA ikDbt/0oIS/kxlIdcYJ01xuMrDXf1jFhmGZdocUoNJkgLb1iFAl5daV8MQOrqciG+6tnLeZK HY4xCBoigV7E8KwEE5yUfxBS0yRreNb+pjKtX6pSr1Z/dIo+td/sHfEHffaMUIRNvJlBeqaj BX7ZveskVFafmErkH7HC+7ErIaqoM4aOh/Z0qXbMEjFsWA5yVXvCoJWSHFImL9Bo6PbMGpI0 9eBrkNa1fd6RGcktrX6KNfGZ2POECmKGLTyDC8/kb180YpDJERN48S0QBa3Rvt06ozNgFgZF Wvu5Li5PpY/t/M7AAkLiVTtlhZnJWyEJrQi9O2nXTzlG1PeqGH2ahuRxn7txA5j5PHZEZdL1 Z46HaNmN2hZS/oJ69c1DI5Rcww== Organization: ARM Ltd Message-ID: <56a08bd2-6b94-457f-99f7-91ef3fca8804@arm.com> Date: Tue, 11 Jun 2019 10:54:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190611093744.GA9783@ubuntu> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Gen, No idea why I'm being cc'd on this but hey... ;-) On 11/06/2019 10:37, Gen Zhang wrote: > On Thu, May 30, 2019 at 11:39:49AM +0800, Gen Zhang wrote: >> In knav_pool_create(), 'pool->name' is allocated by kstrndup(). It >> returns NULL when fails. So 'pool->name' should be checked. And free >> 'pool' when error. >> >> Signed-off-by: Gen Zhang >> --- >> diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c >> index 8b41837..0f8cb28 100644 >> --- a/drivers/soc/ti/knav_qmss_queue.c >> +++ b/drivers/soc/ti/knav_qmss_queue.c >> @@ -814,6 +814,12 @@ void *knav_pool_create(const char *name, >> } >> >> pool->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL); >> + if (!pool->name) { >> + dev_err(kdev->dev, "failed to duplicate for pool(%s)\n", >> + name); There is no need to output anything, the kernel will be loud enough if you run out of memory. >> + ret = -ENOMEM; >> + goto err_name; >> + } >> pool->kdev = kdev; >> pool->dev = kdev->dev; >> >> @@ -864,6 +870,7 @@ void *knav_pool_create(const char *name, >> mutex_unlock(&knav_dev_lock); >> err: >> kfree(pool->name); >> +err_name: kfree(NULL) is perfectly valid, there is no need to create a second label. Just branch to the existing error label. >> devm_kfree(kdev->dev, pool); >> return ERR_PTR(ret); >> } > Can anyone look into this patch? > > Thanks > Gen > The real question is whether this is actually an error at all. pool->name doesn't seem to be used for anything but debug information, and the printing code can perfectly accommodate a NULL pointer. Thanks, M. -- Jazz is not dead. It just smells funny...