forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/media/pci/ivtv/ivtv-udma.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 User DMA
34
....@@ -5,19 +6,6 @@
56 Copyright (C) 2004 Chris Kennedy <c@groovy.org>
67 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
78
8
- This program is free software; you can redistribute it and/or modify
9
- it under the terms of the GNU General Public License as published by
10
- the Free Software Foundation; either version 2 of the License, or
11
- (at your option) any later version.
12
-
13
- This program is distributed in the hope that it will be useful,
14
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- GNU General Public License for more details.
17
-
18
- You should have received a copy of the GNU General Public License
19
- along with this program; if not, write to the Free Software
20
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
219 */
2210
2311 #include "ivtv-driver.h"
....@@ -104,7 +92,7 @@
10492 {
10593 struct ivtv_dma_page_info user_dma;
10694 struct ivtv_user_dma *dma = &itv->udma;
107
- int i, err;
95
+ int err;
10896
10997 IVTV_DEBUG_DMA("ivtv_udma_setup, dst: 0x%08x\n", (unsigned int)ivtv_dest_addr);
11098
....@@ -123,16 +111,15 @@
123111 return -EINVAL;
124112 }
125113
126
- /* Get user pages for DMA Xfer */
127
- err = get_user_pages_unlocked(user_dma.uaddr, user_dma.page_count,
114
+ /* Pin user pages for DMA Xfer */
115
+ err = pin_user_pages_unlocked(user_dma.uaddr, user_dma.page_count,
128116 dma->map, FOLL_FORCE);
129117
130118 if (user_dma.page_count != err) {
131119 IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n",
132120 err, user_dma.page_count);
133121 if (err >= 0) {
134
- for (i = 0; i < err; i++)
135
- put_page(dma->map[i]);
122
+ unpin_user_pages(dma->map, err);
136123 return -EINVAL;
137124 }
138125 return err;
....@@ -142,9 +129,7 @@
142129
143130 /* Fill SG List with new values */
144131 if (ivtv_udma_fill_sg_list(dma, &user_dma, 0) < 0) {
145
- for (i = 0; i < dma->page_count; i++) {
146
- put_page(dma->map[i]);
147
- }
132
+ unpin_user_pages(dma->map, dma->page_count);
148133 dma->page_count = 0;
149134 return -ENOMEM;
150135 }
....@@ -165,7 +150,6 @@
165150 void ivtv_udma_unmap(struct ivtv *itv)
166151 {
167152 struct ivtv_user_dma *dma = &itv->udma;
168
- int i;
169153
170154 IVTV_DEBUG_INFO("ivtv_unmap_user_dma\n");
171155
....@@ -181,10 +165,7 @@
181165 /* sync DMA */
182166 ivtv_udma_sync_for_cpu(itv);
183167
184
- /* Release User Pages */
185
- for (i = 0; i < dma->page_count; i++) {
186
- put_page(dma->map[i]);
187
- }
168
+ unpin_user_pages(dma->map, dma->page_count);
188169 dma->page_count = 0;
189170 }
190171