From patchwork Fri Apr 8 16:14:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1614981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KZjy26dsyz9sG6 for ; Sat, 9 Apr 2022 02:14:50 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ncrG1-0002V2-GJ; Fri, 08 Apr 2022 16:14:45 +0000 Received: from mail-pl1-f180.google.com ([209.85.214.180]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ncrFz-0002UR-Ef for kernel-team@lists.ubuntu.com; Fri, 08 Apr 2022 16:14:43 +0000 Received: by mail-pl1-f180.google.com with SMTP id c23so8331712plo.0 for ; Fri, 08 Apr 2022 09:14:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oY3vVgmbelaPUrfwafW2oD61ssT1eQiXOPMbhjL1NbY=; b=mHMnVtFgrASk+c9oUwoa9m//cajXa30DWHzrJt/XleZrvDgVSwhcERFB4I2AvZpYtq G4gjWZyno4Z06J/ZAsFC5udzgACv3seg1C4Ugd0+r6r8PpsOGtSPpSpB6zNz7nOrv/6U 4Vl++IHrz+a3TMZck6Pugj7PZc5m4PFhMabrPE7aOKVLlAchvrTToFgjwtqL6JNN2uhA zGzmYcSWbzRFpZUTPX9whWYZeWAPoTpI6jCg1vrNXZND8DmMRF6br+uTl2j8cjy0OJjJ lVVh/rnd4zy2bPZd51HJrqylHKcA+i+S+7Q3TFHpF6h2pAmsPkgr7dG7QRvMdVE/9mie r8FQ== X-Gm-Message-State: AOAM533MGcjvcQGQC6IWlwBIjQYq1KQCao1uyWXn588UhCZs8hiL8RvR G3igwkMrIS+2IgOTG33d39+fT9+y0WI= X-Google-Smtp-Source: ABdhPJxwXkGdUBBD1Xl+FsCAffnn/MKXPRN8ENpNHByKPaPssyXkUhNEnJpoV08sOcpMf+0fqFSsdw== X-Received: by 2002:a17:90b:4f86:b0:1c6:b3eb:99a3 with SMTP id qe6-20020a17090b4f8600b001c6b3eb99a3mr22998513pjb.66.1649434481462; Fri, 08 Apr 2022 09:14:41 -0700 (PDT) Received: from localhost (114-40-204-238.dynamic-ip.hinet.net. [114.40.204.238]) by smtp.gmail.com with ESMTPSA id n11-20020a638f0b000000b00398b4d7b9dbsm22193906pgd.75.2022.04.08.09.14.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Apr 2022 09:14:41 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/1][SRU][Jammy] UBUNTU: SAUCE: media: pci: intel: Avoid UBSAN warnings of index bound and shift Date: Sat, 9 Apr 2022 00:14:36 +0800 Message-Id: <20220408161436.2213276-2-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220408161436.2213276-1-vicamo.yang@canonical.com> References: <20220408161436.2213276-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.180; envelope-from=vicamo@gmail.com; helo=mail-pl1-f180.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Hao Yao BugLink: https://bugs.launchpad.net/bugs/1958006 UBSAN is default enabled on 5.15 kernel on Ubuntu. The code to allocate resources in IPU can cause some array-index-out-of-bounds and shift-out-of-bounds warnings, so it needs to be fixed. Signed-off-by: Hao Yao (cherry picked from commit 8dcb7d8df28fd311a72f3d996b02231e38aac8a7 github.com/intel/ipu6-drivers) Signed-off-by: You-Sheng Yang --- drivers/media/pci/intel/ipu6/ipu-resources.c | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/media/pci/intel/ipu6/ipu-resources.c b/drivers/media/pci/intel/ipu6/ipu-resources.c index dfe4fde7e83f..07d5aff3b6ce 100644 --- a/drivers/media/pci/intel/ipu6/ipu-resources.c +++ b/drivers/media/pci/intel/ipu6/ipu-resources.c @@ -244,7 +244,7 @@ static int __alloc_one_resrc(const struct device *dev, unsigned long retl; if (resource_req <= 0) - return 0; + return -ENXIO; if (alloc->resources >= IPU_MAX_RESOURCES) { dev_err(dev, "out of resource handles\n"); @@ -285,7 +285,7 @@ static int ipu_psys_allocate_one_dfm(const struct device *dev, unsigned long p = 0; if (dfm_bitmap_req == 0) - return 0; + return -ENXIO; if (alloc->resources >= IPU_MAX_RESOURCES) { dev_err(dev, "out of resource handles\n"); @@ -346,7 +346,7 @@ static int __alloc_mem_resrc(const struct device *dev, unsigned long retl; if (memory_resource_req <= 0) - return 0; + return -ENXIO; if (alloc->resources >= IPU_MAX_RESOURCES) { dev_err(dev, "out of resource handles\n"); @@ -488,7 +488,7 @@ int ipu_psys_try_allocate_resources(struct device *dev, ret = __alloc_one_resrc(dev, process, &pool->dev_channels[id], &pm, id, alloc); - if (ret) + if (ret && ret != -ENXIO) goto free_out; } } @@ -498,7 +498,7 @@ int ipu_psys_try_allocate_resources(struct device *dev, ret = ipu_psys_allocate_one_dfm (dev, process, &pool->dfms[id], &pm, id, alloc); - if (ret) + if (ret && ret != -ENXIO) goto free_out; } } @@ -522,7 +522,7 @@ int ipu_psys_try_allocate_resources(struct device *dev, &pool->ext_memory[bank], &pm, mem_type_id, bank, alloc); - if (ret) + if (ret && ret != -ENXIO) goto free_out; } } @@ -626,6 +626,9 @@ int ipu_psys_allocate_resources(const struct device *dev, ret = __alloc_one_resrc(dev, process, &pool->dev_channels[id], &pm, id, alloc); + if (ret == -ENXIO) + continue; + if (ret) goto free_out; @@ -643,6 +646,9 @@ int ipu_psys_allocate_resources(const struct device *dev, ret = ipu_psys_allocate_one_dfm(dev, process, &pool->dfms[id], &pm, id, alloc); + if (ret == -ENXIO) + continue; + if (ret) goto free_out; @@ -678,6 +684,9 @@ int ipu_psys_allocate_resources(const struct device *dev, &pool->ext_memory[bank], &pm, mem_type_id, bank, alloc); + if (ret == -ENXIO) + continue; + if (ret) goto free_out;