Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp136523rwd; Fri, 19 May 2023 16:55:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7tKVyUKWi4XSW5F1vV0tphk2Y7OxtNfQWXZCJqxtFGm6ntbICGnJcBBP543zHitUturxaK X-Received: by 2002:a05:6a20:7215:b0:d9:250:665c with SMTP id y21-20020a056a20721500b000d90250665cmr2933484pzb.15.1684540506802; Fri, 19 May 2023 16:55:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684540506; cv=none; d=google.com; s=arc-20160816; b=RtrGAdDudUGRI69VNSUpLyzQlEE51jsYEhGW3ara8J/Na0xj4G7+AH1zziNsQYZngA EWH/A3zhKLbo4le2lNy3xcoZEuL4t6MW3v5gZCec1novRI4Fq5sOkFDOgvUgE7rXrvTk +/ADrJL6C1H1i1Pc4x/Pe0DdNU0cR+mLcXbYdVOyJf6t+3LkAnh3BwQz8+14yX9dkMRM rs6aw2DudrQpCVvzuOU2NQAN5T507VYEBcn2namxSBL0QuAzgpqcVhT1DimkpDHwWBv9 UTbjdXZlM9YikArE6wZsmhjjMyM5LLpSerOaGn6dGFiur4Z93+VZeqqLR/i5+IlwtnI4 x9Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=j+/I1DakxPrd+okwwNtUEXRwJ7ucYEoX+rOCHphwT6I=; b=sLrh1UIRzzoRDD5WQ8ShUk1dD2NPQGNqsdQAoxWw3wRotE1CChlDxmvyPf+GJbMQfN fjT/Ur0YdCVBMkBqz4PekcTrK8HGfg4ggftyN022xklHNsuu0jebV8gSmRXDJm9m2Nn5 Rr0wCM0rOp80KAVfrYhOW9ByBXp9crdvsvWk2MRnKGgFWj0yJuzKHryHgG6ognWeMW3e 9cjmq9ceqUv4L5ZzeWGp7nEMDMWhU0nDqGt8LvWqTQOk3C7oYfF5Kw0UVcu7hCSvUWAP e2s4w30I1pH7tv8sQufdj2Zq4f5f8rvsMpJIof8Ql+JZO6OJg6DdOwdozEs1H0RRNCS+ F2Sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs64-20020a632843000000b005349009f1desi407284pgb.354.2023.05.19.16.54.52; Fri, 19 May 2023 16:55:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229609AbjESXjy (ORCPT + 99 others); Fri, 19 May 2023 19:39:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230221AbjESXjw (ORCPT ); Fri, 19 May 2023 19:39:52 -0400 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B97A1B3; Fri, 19 May 2023 16:39:51 -0700 (PDT) Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-51b0f9d7d70so3530272a12.1; Fri, 19 May 2023 16:39:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684539591; x=1687131591; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=j+/I1DakxPrd+okwwNtUEXRwJ7ucYEoX+rOCHphwT6I=; b=B4U12YwCYTeNLFHf+F6NnDTiONqlnERt6n4jt+H00j4OT/7WnLUBOFVSve7MZHPsAc ZaHn2Pu2wT8QFbrH2uXUG12KjsLeqfHtjkuGchc/B49nW3FsIdcvFKdDVoISs8vkPd2g 39Hv+OQ0gqBbU/KMrTnHQjHV/mKMZBmcYrewkAF1tloXWajUi6AZvKYlYkuwDqx45v3q qQy01bhau/+1mLLUKrpOin/W8W7vai43rGMnUHAWxKx1m2TGKFje2BbylHP2a73klI9y pn9QwOQknSR+yGKYKSOs/mmNKcXcpIKRkbjvtZTb+JbhADCsWFrLLDqOIC02Qudc1YBa volw== X-Gm-Message-State: AC+VfDzZEqG1MZAW5kj2oZe8W1WP/NaBi391i2HdbVV9vLwSMIOrpN7+ 1lw/0wesZPNfnSorOD1c8d5EnsrDZMIeSrVO X-Received: by 2002:a17:902:d4c6:b0:1a5:150f:8558 with SMTP id o6-20020a170902d4c600b001a5150f8558mr4038822plg.17.1684539590542; Fri, 19 May 2023 16:39:50 -0700 (PDT) Received: from dev-linux.lan (cpe-70-95-21-110.san.res.rr.com. [70.95.21.110]) by smtp.gmail.com with ESMTPSA id t5-20020a170902e84500b001960706141fsm170742plg.149.2023.05.19.16.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 16:39:49 -0700 (PDT) Date: Fri, 19 May 2023 16:39:47 -0700 From: Sukrut Bellary To: Dan Carpenter Cc: Srinivas Kandagatla , Abel Vesa , Amol Maheshwari , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Shuah Khan Subject: Re: [PATCH] misc: fastrpc: Fix double free of 'buf' in error path Message-ID: References: <20230518100829.515143-1-sukrut.bellary@linux.com> <9194ebdf-f335-4cd6-bf89-bb4f86a57784@kili.mountain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 19, 2023 at 01:58:10PM +0300, Dan Carpenter wrote: > This is unrelated but I was looking through the driver and I notice > a bunch of code doing: > > grep 'return ret ?' drivers/firmware/ -R > > return ret ? : res.result[0]; > > "ret" here is a kernel error code, and res.result[0] is a firmware > error code. Mixing error codes is a dangerous thing. I was reviewing > some of the callers and the firmware error code gets passed quite far > back into the kernel to where we would only expect kernel error codes. > > Presumably the firmware is returning positive error codes? To be honest, > I am just guessing. It's better to convert custom error codes to kernel > error codes as soon as possible. I am just guessing. Sukrut, do you > think you could take a look? If the callers do not differentiate > between negative kernel error codes and positive custom error codes then > probably just do: > > if (res.result[0]) > ret = -EIO; // -EINVAL? > return ret; > Thanks, Dan, for sharing your findings. Yes, sure, I will take a look. Regards, Sukrut Bellary > Also there are a couple places which do: > > return ret ? false : !!res.result[0]; > > Here true means success and false means failure. So the !! converts > a firmware error code to true when it should be false so that's a bug. > Quadruple negatives are confusing... It should be: > > if (ret || res.result[0]) > return false; > return true; > > regards, > dan carpenter >