From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f46.google.com (mail-yx1-f46.google.com [74.125.224.46]) (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 1DE2A326927 for ; Thu, 25 Jun 2026 08:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782377849; cv=none; b=dtUa0AwdiCH3c9aLD2qqaOrfk3ccEZF9kq6MFxkeGWuyWp0CbBEC8RxLbsvZ4Cepa7VtCL3uTKFRewwBrz7YHmXIVlFc/mjkBdZ7hAOOx6p1zFrn/momCEvEQRTac68ArcomE/WwHf1GmVfPtEdjPx9foX4FRLxGWWz0PJaW/JE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782377849; c=relaxed/simple; bh=z3ifyXo4P4eBwNsPbrBccOs5hNTXuDWJynVPrxskX78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hbS+mkNeHS5VwbGnYzVODfk9JREI4M5/L6whMsvY7aT9EQSjJJpZeNo55d2wDST3ucy3o1c0v0E1gQ5O6eHB9s1oBnziGSQpANuW9K7Zqu9IeDQ1nhnxHDW+bpUr0c57wt2sD9/aotZVqorrxjvTBWRLY6PIkQ8zi5eiTTTsZq0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZZf0L1Zx; arc=none smtp.client-ip=74.125.224.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZZf0L1Zx" Received: by mail-yx1-f46.google.com with SMTP id 956f58d0204a3-664346e66daso1580793d50.0 for ; Thu, 25 Jun 2026 01:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782377845; x=1782982645; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YCYjeG3UoXuLJvf4tB6q96AYo9bWZwxnIXnqLkpJp/o=; b=ZZf0L1ZxHi5kzTyxX+QGcQdakZhBt2nHzu8s2gHK94spNSevw8zxb/KmPwD/J9AyrV HMdRRtdpKcOyWvysL9cuXvDf5QyGicwh5OlsRBpR/xanV0Fvpxdp4Wb+W61Y4lZGBQYg K2LOTKSMuM9+FVfL+FXzVTkEyacc7IYf+8T3EcNU91juRqfIBJTIrONysIL4/gCo2S7H 99SeVJnAg22Jp+7RIbYdBjKBkWS0JJ5wTb03OO8PKOQ4W0IjXjKPoh6qYpLR8AUdnR9X rg3rcKVy0f6caeI9nDyxyJfDcUqsDfaLE/x9zEQothxCjzfeiKOc5hEJoVGRZsWWYdOG +V1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782377845; x=1782982645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=YCYjeG3UoXuLJvf4tB6q96AYo9bWZwxnIXnqLkpJp/o=; b=liklnY/BF/BmXvxNL/XZTD+wE5p38UdF544CDxjxc/E3XRiq2hXVkS7teVat29B7SZ InV8Aply3zhsvlciiUjLFF/qySrC5OA2hjdLx1TN2mAloCxdj8AFoA0kE0F5vlEYt4TO FL3nItwhDTIqEeDbHyd5R2Mgh+L0Jo/5X8FYMSfFU0bbizYKdAOEQpuRlBs9J1q5p/ns bmLQMm/o38SsyQMu/8C75NSYF2sVHwl2URaBh38XXR7s9WiARuIiytQOrn0dSS9996wc ur621Jrn667F7ed7gclDB1r1IaFCQypKPBQo2N6758jbbxZ7K+PJbralZdXPccDKRZbb sDTQ== X-Forwarded-Encrypted: i=1; AHgh+RpAyEtrBgfi0NRJZku6qoRJovI8BxOHRVlAFZLx2HOmqFSVARhz+qep8U4KW5aoxrTNVbEylVo+UdmJD3I=@vger.kernel.org X-Gm-Message-State: AOJu0YyJPiTtUHt95vAA7ffNEpRTH1vCIAmE0/kSFSlWz/mGyH1O9E7K 7x0LLmcS7xXKba6gTHjujBofexgAp4bJ5VcrxT5ErKStb5UnwOzjd0z3+4RzzWTCpP7Phw== X-Gm-Gg: AfdE7cl55IFxqMkL6j8PoFyL4+7XzLs6xKmi+19vbCfVWedL/IYgT17t9cXt1NUvnUh ga/If1qf/W9TZN42UxamCC0sP2xqOubh9GbZQ/qFfKV7dJPQwmJuuPBwglKvXaIwziUy0B3zaQo +nCYQT2rszlhjv/jTREgAy+8PX9h1+xlToVi3MQeOYVgaTEvMgisTb7UG1OVi/C3neB+twdqKTq D1y1T196yK44S4NAEKTqT3SrRO06v1hOCGawMHCZRfQkH/rj3+/PeHPXk9Thg69R509JJKaFmUX THXvIFzvso+wzEAhgxHNxNcwtT+9UR1/Q7tz1dzKHaXp43i78eXT24WfDQMRhr6X5FTbufipVF0 +DVJgMmhN9kQIywwrNIP95Tj3WNNksM/d8oQyfdORe5yzhVluFKCwhsaQ9pNydK09xNMocSPtMi zGBy7kYpwuKFJujyMT8wl16+cu0cfPaj9Ttrvr X-Received: by 2002:a53:ac9b:0:b0:660:5a7b:9d7f with SMTP id 956f58d0204a3-66487c7810amr1149739d50.15.1782377845163; Thu, 25 Jun 2026 01:57:25 -0700 (PDT) Received: from Dev-Null-MSI ([2a0d:3344:52ac:a808:98a4:4381:be45:536f]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6647f785f6bsm1105061d50.6.2026.06.25.01.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 01:57:24 -0700 (PDT) From: Yousef Alhouseen To: Srinivas Kandagatla , Amol Maheshwari Cc: Konrad Dybcio , Arnd Bergmann , Greg Kroah-Hartman , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Yousef Alhouseen Subject: [PATCH 2/3] misc: fastrpc: fix map cleanup paths Date: Thu, 25 Jun 2026 10:56:58 +0200 Message-ID: <20260625085659.4469-2-alhouseenyousef@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260625085659.4469-1-alhouseenyousef@gmail.com> References: <20260625085659.4469-1-alhouseenyousef@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit fastrpc_create_maps() can attach dma-bufs for every scalar argument, including handle arguments beyond the input and output buffer count. fastrpc_context_free() only dropped references up to nbufs, leaving handle maps attached after invoke cleanup. fastrpc_map_attach() also falls through to fastrpc_map_put() after manually detaching and putting the dma-buf on late errors. Leave the map object in a state that matches the resources still owned by the release path so the attachment and dma-buf are not released twice. Signed-off-by: Yousef Alhouseen --- drivers/misc/fastrpc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 8992b5c0c..50f90e17e 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -580,7 +580,7 @@ static void fastrpc_context_free(struct kref *ref) cctx = ctx->cctx; fl = ctx->fl; - for (i = 0; i < ctx->nbufs; i++) + for (i = 0; i < ctx->nscalars; i++) fastrpc_map_put(ctx->maps[i]); if (ctx->buf) @@ -917,7 +917,7 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd, table = dma_buf_map_attachment_unlocked(map->attach, DMA_BIDIRECTIONAL); if (IS_ERR(table)) { err = PTR_ERR(table); - goto map_err; + goto detach_err; } map->table = table; @@ -966,9 +966,15 @@ static int fastrpc_map_attach(struct fastrpc_user *fl, int fd, return 0; map_err: + dma_buf_unmap_attachment_unlocked(map->attach, map->table, + DMA_BIDIRECTIONAL); + map->table = NULL; +detach_err: dma_buf_detach(map->buf, map->attach); + map->attach = NULL; attach_err: dma_buf_put(map->buf); + map->buf = NULL; get_err: fastrpc_map_put(map); -- 2.54.0