@@ -132,33 +132,6 @@ virtiovf_pci_bar0_rw(struct virtiovf_pci_core_device *virtvdev,
132132 return ret ? ret : count ;
133133}
134134
135- static bool range_intersect_range (loff_t range1_start , size_t count1 ,
136- loff_t range2_start , size_t count2 ,
137- loff_t * start_offset ,
138- size_t * intersect_count ,
139- size_t * register_offset )
140- {
141- if (range1_start <= range2_start &&
142- range1_start + count1 > range2_start ) {
143- * start_offset = range2_start - range1_start ;
144- * intersect_count = min_t (size_t , count2 ,
145- range1_start + count1 - range2_start );
146- * register_offset = 0 ;
147- return true;
148- }
149-
150- if (range1_start > range2_start &&
151- range1_start < range2_start + count2 ) {
152- * start_offset = 0 ;
153- * intersect_count = min_t (size_t , count1 ,
154- range2_start + count2 - range1_start );
155- * register_offset = range1_start - range2_start ;
156- return true;
157- }
158-
159- return false;
160- }
161-
162135static ssize_t virtiovf_pci_read_config (struct vfio_device * core_vdev ,
163136 char __user * buf , size_t count ,
164137 loff_t * ppos )
@@ -178,16 +151,18 @@ static ssize_t virtiovf_pci_read_config(struct vfio_device *core_vdev,
178151 if (ret < 0 )
179152 return ret ;
180153
181- if (range_intersect_range (pos , count , PCI_DEVICE_ID , sizeof (val16 ),
182- & copy_offset , & copy_count , & register_offset )) {
154+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_DEVICE_ID ,
155+ sizeof (val16 ), & copy_offset ,
156+ & copy_count , & register_offset )) {
183157 val16 = cpu_to_le16 (VIRTIO_TRANS_ID_NET );
184158 if (copy_to_user (buf + copy_offset , (void * )& val16 + register_offset , copy_count ))
185159 return - EFAULT ;
186160 }
187161
188162 if ((le16_to_cpu (virtvdev -> pci_cmd ) & PCI_COMMAND_IO ) &&
189- range_intersect_range (pos , count , PCI_COMMAND , sizeof (val16 ),
190- & copy_offset , & copy_count , & register_offset )) {
163+ vfio_pci_core_range_intersect_range (pos , count , PCI_COMMAND ,
164+ sizeof (val16 ), & copy_offset ,
165+ & copy_count , & register_offset )) {
191166 if (copy_from_user ((void * )& val16 + register_offset , buf + copy_offset ,
192167 copy_count ))
193168 return - EFAULT ;
@@ -197,16 +172,18 @@ static ssize_t virtiovf_pci_read_config(struct vfio_device *core_vdev,
197172 return - EFAULT ;
198173 }
199174
200- if (range_intersect_range (pos , count , PCI_REVISION_ID , sizeof (val8 ),
201- & copy_offset , & copy_count , & register_offset )) {
175+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_REVISION_ID ,
176+ sizeof (val8 ), & copy_offset ,
177+ & copy_count , & register_offset )) {
202178 /* Transional needs to have revision 0 */
203179 val8 = 0 ;
204180 if (copy_to_user (buf + copy_offset , & val8 , copy_count ))
205181 return - EFAULT ;
206182 }
207183
208- if (range_intersect_range (pos , count , PCI_BASE_ADDRESS_0 , sizeof (val32 ),
209- & copy_offset , & copy_count , & register_offset )) {
184+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_BASE_ADDRESS_0 ,
185+ sizeof (val32 ), & copy_offset ,
186+ & copy_count , & register_offset )) {
210187 u32 bar_mask = ~(virtvdev -> bar0_virtual_buf_size - 1 );
211188 u32 pci_base_addr_0 = le32_to_cpu (virtvdev -> pci_base_addr_0 );
212189
@@ -215,8 +192,9 @@ static ssize_t virtiovf_pci_read_config(struct vfio_device *core_vdev,
215192 return - EFAULT ;
216193 }
217194
218- if (range_intersect_range (pos , count , PCI_SUBSYSTEM_ID , sizeof (val16 ),
219- & copy_offset , & copy_count , & register_offset )) {
195+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_SUBSYSTEM_ID ,
196+ sizeof (val16 ), & copy_offset ,
197+ & copy_count , & register_offset )) {
220198 /*
221199 * Transitional devices use the PCI subsystem device id as
222200 * virtio device id, same as legacy driver always did.
@@ -227,8 +205,9 @@ static ssize_t virtiovf_pci_read_config(struct vfio_device *core_vdev,
227205 return - EFAULT ;
228206 }
229207
230- if (range_intersect_range (pos , count , PCI_SUBSYSTEM_VENDOR_ID , sizeof (val16 ),
231- & copy_offset , & copy_count , & register_offset )) {
208+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_SUBSYSTEM_VENDOR_ID ,
209+ sizeof (val16 ), & copy_offset ,
210+ & copy_count , & register_offset )) {
232211 val16 = cpu_to_le16 (PCI_VENDOR_ID_REDHAT_QUMRANET );
233212 if (copy_to_user (buf + copy_offset , (void * )& val16 + register_offset ,
234213 copy_count ))
@@ -270,19 +249,20 @@ static ssize_t virtiovf_pci_write_config(struct vfio_device *core_vdev,
270249 loff_t copy_offset ;
271250 size_t copy_count ;
272251
273- if (range_intersect_range (pos , count , PCI_COMMAND , sizeof (virtvdev -> pci_cmd ),
274- & copy_offset , & copy_count ,
275- & register_offset )) {
252+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_COMMAND ,
253+ sizeof (virtvdev -> pci_cmd ),
254+ & copy_offset , & copy_count ,
255+ & register_offset )) {
276256 if (copy_from_user ((void * )& virtvdev -> pci_cmd + register_offset ,
277257 buf + copy_offset ,
278258 copy_count ))
279259 return - EFAULT ;
280260 }
281261
282- if (range_intersect_range (pos , count , PCI_BASE_ADDRESS_0 ,
283- sizeof (virtvdev -> pci_base_addr_0 ),
284- & copy_offset , & copy_count ,
285- & register_offset )) {
262+ if (vfio_pci_core_range_intersect_range (pos , count , PCI_BASE_ADDRESS_0 ,
263+ sizeof (virtvdev -> pci_base_addr_0 ),
264+ & copy_offset , & copy_count ,
265+ & register_offset )) {
286266 if (copy_from_user ((void * )& virtvdev -> pci_base_addr_0 + register_offset ,
287267 buf + copy_offset ,
288268 copy_count ))
0 commit comments