From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D76F1D63C1 for ; Thu, 24 Oct 2024 12:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729774634; cv=none; b=ALSsYVb+m/E0Cd5v//3P4tgXqllkBD++cNtepupZRABul7h0fJTbCmIjYZ3NPY1VVzc6J3+kihh7Kr8DLRW+mzNQErigNBjHe8NkMspHlIl7pD+reaXY2WL4ST1rqNsS+UTKlptoPY1cTjzuGH1XM0GSWI0VlFIBb+NK5kRzBuY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729774634; c=relaxed/simple; bh=fqEoIh+dgxuIFMBN6cyueAHztwW8N9qpgQuWpBDpkGg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=uBrudL4FRj34xrdmQbGK/ldnRoaM+mf1x0bu2cCv2D7cQxT1ZvYR7a6NW6z6Muqql1l51cT/7HSlA1/Ch1sHw0zIwWeLw12Z8PKnSdoHavtCCLtk7bc4Cujeynjf8T3R/Csxm9YPMYJoCZJLb8Ylmo+s/v/9WJ4Lvtp/q/jjEV8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=UkPfp5hf; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UkPfp5hf" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4314b316495so8419075e9.2 for ; Thu, 24 Oct 2024 05:57:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729774630; x=1730379430; 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=Il7PJErLFSTwbIIob3qN4HBHgXZw+lBDkmE4mAtAfRs=; b=UkPfp5hf6WaTkvW59YpE3aoJ91OOWShbeLxAjWJLdNKW0bzejpu9qowgNXAMpoSSCQ FCZHdbMLta73Zk8L6Ca2hl9BA171cJFWgTKEsxeMgPuq3Q2dy/NQo2HKnDmHLWWCJCq4 rkvw1k6ARIlcKyCerjk2x4V9jSFU+3Qz/VnIMoGFw4iEJKQGRz3FtK4rvNuUHraRHm4M 7GTlZmPCz2zHdvYv3HUVVQDIE7dHE/5soHstNZkJ/xWOco+/3ONI3lM075mQ1keIsGjd EJxSvx4Qusg/z6L26QDPz8142kh5JFnElAgcFRfed4kn3Xp+4aY9IQxhLWSPjj6I3igY FAfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729774630; x=1730379430; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Il7PJErLFSTwbIIob3qN4HBHgXZw+lBDkmE4mAtAfRs=; b=at/rM9CiDjnLcKaqCOSS3Tk8eWy5EqlSddTjWz7RcI8WTz7Zk5lU4Y60aB5O3M9SkO bteHYq8x5xsZgzKM+fixHO4d9GL7B2Bi/euku/aCR2zWcNabAmwnaORbwi9cfh9w0aWC s6M0FqOtY5UE7MD9DnnM8eeB2z/6dgR1/rHkLb5jH+hJvq2IVMfUQJ/08b/jJ4NgEM6l 2Uf/VOjtKDBx5no6Vopdz/s+QsWec5Lfmrqs3UtgCuMEadLNovunJQckuVL4R9t3j7FV 5+oI7N4Vbqbr9Ces/1j3543ltgg5aE3ODXfDwv7yomu0w29T4otgSnsP8ZSgiDU2Gjsb KESA== X-Gm-Message-State: AOJu0YyJ+xLQQmxmVucuyQzoxWl0JOhoUexwtoEIoF1HL6XW9CbIlfre Nbl2bhBd5GPXDl9O5yBG9Xi+PENsVOFEixTSMTHIpCwXtGluPkLhyhjQIdUlt/8= X-Google-Smtp-Source: AGHT+IFcCk4ndxwV1eYGLw1HNaQkSMmcWJhjmwBTuLmOTNWjeZKVSceV3A3F12X0UF///gySqGg5IQ== X-Received: by 2002:a05:600c:35cd:b0:430:52ec:1e41 with SMTP id 5b1f17b1804b1-4318415c0acmr57933815e9.17.1729774630318; Thu, 24 Oct 2024 05:57:10 -0700 (PDT) Received: from [192.168.10.46] (146725694.box.freepro.com. [130.180.211.218]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4318b5431ecsm17580855e9.5.2024.10.24.05.57.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Oct 2024 05:57:09 -0700 (PDT) Message-ID: <9ba3fa17-57c3-41e9-9e19-33fa105a179e@linaro.org> Date: Thu, 24 Oct 2024 14:57:09 +0200 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] thermal/lib: Fix memory leak on error in thermal_genl_auto() To: Markus Elfring , linux-pm@vger.kernel.org, Lukasz Luba , "Rafael J. Wysocki" Cc: LKML , Zhang Rui References: <20241024105938.1095358-1-daniel.lezcano@linaro.org> <45265aca-7371-455f-819f-c4d68cbb089b@web.de> Content-Language: en-US From: Daniel Lezcano In-Reply-To: <45265aca-7371-455f-819f-c4d68cbb089b@web.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 24/10/2024 14:02, Markus Elfring wrote: >> The function thermal_genl_auto() does not free the allocated message >> in the error path. Fix that by putting a out label and jump to it >> which will free the message instead of directly returning an error. > > Would you like to add any tags (like “Fixes” and “Cc”) accordingly? > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.12-rc4#n145 > > > … >> +++ b/tools/lib/thermal/commands.c >> @@ -375,27 +375,30 @@ static thermal_error_t thermal_genl_auto(struct thermal_handler *th, cmd_cb_t cm >> struct cmd_param *param, >> int cmd, int flags, void *arg) >> { >> + thermal_error_t ret = THERMAL_ERROR; >> struct nl_msg *msg; >> void *hdr; >> >> msg = nlmsg_alloc(); >> if (!msg) >> - return THERMAL_ERROR; >> + goto out; > … > > Is it really reasonable to pass a null pointer (from a failed function call) > to a subsequent nlmsg_free() call? You are right, I should return here :S > Can it be more appropriate to return directly in such an error case? > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.12-rc4#n532 > > Regards, > Markus -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog