Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1375366rwb; Thu, 11 Aug 2022 22:59:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR4DICdRfVqJMdV30nEAdL0ruCeA3e1nEzJFqWOnuyb2AWp+70+oiFY/Y5FhNhFnHRANaNA/ X-Received: by 2002:a17:906:cc0d:b0:730:d6f3:277a with SMTP id ml13-20020a170906cc0d00b00730d6f3277amr1537564ejb.579.1660283993501; Thu, 11 Aug 2022 22:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660283993; cv=none; d=google.com; s=arc-20160816; b=tHNZEJ+4trlLPTYOW1cn1WMQwnM6WbWZKBSLgpuvJwWe1mn+wNI0v+m7eMosXvwLFr 2wm2BF88oeGoGkN6qfpPqQzxpfbm6yYvF4uewM/kt1nMQ9Th6aNyxjtohJiXiUZL9eYF 23bf6TUyJ5tpWqn8TwUVP3nsLwe6p6X/8zHQLoug9U9Mgm1QyA3qxEHE0tGnsxJHEPP2 8Wjt3nFU78nYaeEN7HDh4ABtX/NRw1cLu+qSs30OvUuewWbgGrbUm86z2R3SL+RkVnll AKJHSXpwJVHjor+v1R+07rve5f6XLqFrKoIj+5ynHiHHwthoIgD6Kkxg9Gyn5ZrMSq3R T4Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:cc:content-transfer-encoding :mime-version:message-id:date:subject:dkim-signature; bh=HEmnO6gKg/Ny8un1UXhsJJIoNDtb7QUrGLbN/Rj+U2s=; b=oUzo3LQMLfohma0Damfo90x8/nmPcZE0Z2zW4IAuqClFDs7Pcz/bwtkze7Vzq8Fk9Y BxAvS4PPCcvMf4koCj9HU/OICRrBsL1hJrDVOXmihmajUX5jVuYSex8dz+cKEBfXAAXC wA2uI4eQBhc/VPg+D9ozDnZ6wIYGTvmNjTo8cKNWKHdjJAMh5X5z9jFAeqSqWIc4l5EM mfJSenIP3IKTYrGfz5CIENUpZuUta47IPT8EA202PANF8nJKhAU/EZEhoKWi1OrMEpc8 s5yjWe7BUlsuOMQsQvy0biexE/XxkTQQr2h9l4bACTf2hb6j+IcqsYmTpsMp+ujyLjvL StOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=S6h2Jsqk; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-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 ne28-20020a1709077b9c00b0072b8009c081si1168704ejc.245.2022.08.11.22.59.09; Thu, 11 Aug 2022 22:59:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=S6h2Jsqk; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236888AbiHLFyx (ORCPT + 99 others); Fri, 12 Aug 2022 01:54:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236835AbiHLFyw (ORCPT ); Fri, 12 Aug 2022 01:54:52 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19ABBA222B for ; Thu, 11 Aug 2022 22:54:51 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id m2so18815006pls.4 for ; Thu, 11 Aug 2022 22:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=to:from:cc:content-transfer-encoding:mime-version:message-id:date :subject:from:to:cc; bh=HEmnO6gKg/Ny8un1UXhsJJIoNDtb7QUrGLbN/Rj+U2s=; b=S6h2JsqkYWxvS7jC1PPYrCoWtVa1c7jhqkVfdgVTRawsQeU2o7qd8syCitbKL3Igry a2vspnYwiX6atjvhYOj/vgZm9OOs8OD2WVJ/uQMFT1JSzXM/f6+wpg5tjONYx5mXVrYk QMx5u3F0tiwy+Pgj/g0dpXjvsnBKPsStW07oA+hI2mlUWmshJ9YYA8VYd58ZYpT9Sff+ soe+nCeH5MvE3QIats2gqq3natPebdib/4PCZ+ZVA3LIKmcaYBq9+ZZ0aGOcCufe2Zbk 1agEwVe66MkKDSIryjo+6X+jlL2BoyUqn4gP4pMrGcv3ahE2DIJVIeuNibm5w0pb9rjy ysqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:from:cc:content-transfer-encoding:mime-version:message-id:date :subject:x-gm-message-state:from:to:cc; bh=HEmnO6gKg/Ny8un1UXhsJJIoNDtb7QUrGLbN/Rj+U2s=; b=Kdj7NdGfZ9ALTgmUEirKGtxNwL5S9DyZDSq2PEN176s92l42hsqHH8YW7iXrrvYfuX JE9o8K68+enPDaNFm8EgqKeo4gTVidsX2ivGrMrZi/0F5+FDA7uEq8SaMsPBsKP+fxfH 2Gz4kskdPkLUIE6b/uBks5Nuh5Q70GLjG2DzswstgqOOU98+IkcLBMx45gcPWPzJsKzw 8f0aNgLXacaYO9hueEfjAjAID1XYkbTbR7mf05wNRqJQGfjdM1UWxEL5YCtRmF/ug0dd Gx51GeBrtPn00UwehlqieTJF1W1HyhKx4g+pAH6Wx6s6kWw1ZzeOfH65qf5CU3mX66+6 v+gQ== X-Gm-Message-State: ACgBeo1QvnEykodfGOv94VzoYDR5KdxjbhLMc1lABzCNJqkcpeqir32V pQvR9QGIAR0GMoBj8p49Mxbv3w== X-Received: by 2002:a17:902:b607:b0:170:c7fc:388a with SMTP id b7-20020a170902b60700b00170c7fc388amr2474205pls.29.1660283690611; Thu, 11 Aug 2022 22:54:50 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id z185-20020a6333c2000000b0041aeb36088asm659096pgz.16.2022.08.11.22.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 22:54:50 -0700 (PDT) Subject: [PATCH] Bluetooth: L2CAP: Elide a string overflow warning Date: Thu, 11 Aug 2022 22:52:49 -0700 Message-Id: <20220812055249.8037-1-palmer@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: luiz.dentz@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux@rivosinc.com, Palmer Dabbelt From: Palmer Dabbelt To: marcel@holtmann.org, johan.hedberg@gmail.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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-bluetooth@vger.kernel.org From: Palmer Dabbelt Without this I get a string op warning related to copying from a possibly NULL pointer. I think the warning is spurious, but it's tripping up allmodconfig. In file included from /scratch/merges/ko-linux-next/linux/include/linux/string.h:253, from /scratch/merges/ko-linux-next/linux/include/linux/bitmap.h:11, from /scratch/merges/ko-linux-next/linux/include/linux/cpumask.h:12, from /scratch/merges/ko-linux-next/linux/include/linux/mm_types_task.h:14, from /scratch/merges/ko-linux-next/linux/include/linux/mm_types.h:5, from /scratch/merges/ko-linux-next/linux/include/linux/buildid.h:5, from /scratch/merges/ko-linux-next/linux/include/linux/module.h:14, from /scratch/merges/ko-linux-next/linux/net/bluetooth/l2cap_core.c:31: In function 'memcmp', inlined from 'bacmp' at /scratch/merges/ko-linux-next/linux/include/net/bluetooth/bluetooth.h:347:9, inlined from 'l2cap_global_chan_by_psm' at /scratch/merges/ko-linux-next/linux/net/bluetooth/l2cap_core.c:2003:15: /scratch/merges/ko-linux-next/linux/include/linux/fortify-string.h:44:33: error: '__builtin_memcmp' specified bound 6 exceeds source size 0 [-Werror=stringop-overread] 44 | #define __underlying_memcmp __builtin_memcmp | ^ /scratch/merges/ko-linux-next/linux/include/linux/fortify-string.h:420:16: note: in expansion of macro '__underlying_memcmp' 420 | return __underlying_memcmp(p, q, size); | ^~~~~~~~~~~~~~~~~~~ In function 'memcmp', inlined from 'bacmp' at /scratch/merges/ko-linux-next/linux/include/net/bluetooth/bluetooth.h:347:9, inlined from 'l2cap_global_chan_by_psm' at /scratch/merges/ko-linux-next/linux/net/bluetooth/l2cap_core.c:2004:15: /scratch/merges/ko-linux-next/linux/include/linux/fortify-string.h:44:33: error: '__builtin_memcmp' specified bound 6 exceeds source size 0 [-Werror=stringop-overread] 44 | #define __underlying_memcmp __builtin_memcmp | ^ /scratch/merges/ko-linux-next/linux/include/linux/fortify-string.h:420:16: note: in expansion of macro '__underlying_memcmp' 420 | return __underlying_memcmp(p, q, size); | ^~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Signed-off-by: Palmer Dabbelt --- net/bluetooth/l2cap_core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index cbe0cae73434..be7f47e52119 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -2000,11 +2000,13 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm, } /* Closest match */ - src_any = !bacmp(&c->src, BDADDR_ANY); - dst_any = !bacmp(&c->dst, BDADDR_ANY); - if ((src_match && dst_any) || (src_any && dst_match) || - (src_any && dst_any)) - c1 = c; + if (c) { + src_any = !bacmp(&c->src, BDADDR_ANY); + dst_any = !bacmp(&c->dst, BDADDR_ANY); + if ((src_match && dst_any) || (src_any && dst_match) || + (src_any && dst_any)) + c1 = c; + } } } -- 2.34.1