Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 May 2016 07:46:21 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r300590 - in head/sys/compat/linuxkpi/common: include/linux src
Message-ID:  <201605240746.u4O7kLLi085991@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Tue May 24 07:46:20 2016
New Revision: 300590
URL: https://svnweb.freebsd.org/changeset/base/300590

Log:
  Set "current" for all PCI enumeration callbacks.
  
  Obtained from:	kmacy @
  MFC after:	1 week
  Sponsored by:	Mellanox Technologies

Modified:
  head/sys/compat/linuxkpi/common/include/linux/compat.h
  head/sys/compat/linuxkpi/common/src/linux_compat.c
  head/sys/compat/linuxkpi/common/src/linux_pci.c

Modified: head/sys/compat/linuxkpi/common/include/linux/compat.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/compat.h	Tue May 24 07:21:23 2016	(r300589)
+++ head/sys/compat/linuxkpi/common/include/linux/compat.h	Tue May 24 07:46:20 2016	(r300590)
@@ -31,4 +31,10 @@
 #ifndef	_LINUX_COMPAT_H_
 #define	_LINUX_COMPAT_H_
 
+struct thread;
+struct task_struct;
+
+void linux_set_current(struct thread *td, struct task_struct *t);
+void linux_clear_current(struct thread *td);
+
 #endif	/* _LINUX_COMPAT_H_ */

Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_compat.c	Tue May 24 07:21:23 2016	(r300589)
+++ head/sys/compat/linuxkpi/common/src/linux_compat.c	Tue May 24 07:46:20 2016	(r300590)
@@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$");
 #include <linux/uaccess.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
+#include <linux/compat.h>
 
 #include <vm/vm_pager.h>
 
@@ -380,7 +381,7 @@ kobject_init_and_add(struct kobject *kob
 	return kobject_add_complete(kobj, parent);
 }
 
-static void
+void
 linux_set_current(struct thread *td, struct task_struct *t)
 {
 	memset(t, 0, sizeof(*t));
@@ -388,7 +389,7 @@ linux_set_current(struct thread *td, str
 	task_struct_set(td, t);
 }
 
-static void
+void
 linux_clear_current(struct thread *td)
 {
 	task_struct_set(td, NULL);

Modified: head/sys/compat/linuxkpi/common/src/linux_pci.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_pci.c	Tue May 24 07:21:23 2016	(r300589)
+++ head/sys/compat/linuxkpi/common/src/linux_pci.c	Tue May 24 07:46:20 2016	(r300590)
@@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
 #include <linux/io.h>
 #include <linux/vmalloc.h>
 #include <linux/pci.h>
+#include <linux/compat.h>
 
 static device_probe_t linux_pci_probe;
 static device_attach_t linux_pci_attach;
@@ -120,8 +121,12 @@ linux_pci_attach(device_t dev)
 	struct pci_dev *pdev;
 	struct pci_driver *pdrv;
 	const struct pci_device_id *id;
+	struct task_struct t;
+	struct thread *td;
 	int error;
 
+	td = curthread;
+	linux_set_current(td, &t);
 	pdrv = linux_pci_find(dev, &id);
 	pdev = device_get_softc(dev);
 	pdev->dev.parent = &linux_root_device;
@@ -152,16 +157,21 @@ linux_pci_attach(device_t dev)
 		list_del(&pdev->links);
 		spin_unlock(&pci_lock);
 		put_device(&pdev->dev);
-		return (-error);
+		error = -error;
 	}
-	return (0);
+	linux_clear_current(td);
+	return (error);
 }
 
 static int
 linux_pci_detach(device_t dev)
 {
 	struct pci_dev *pdev;
+	struct task_struct t;
+	struct thread *td;
 
+	td = curthread;
+	linux_set_current(td, &t);
 	pdev = device_get_softc(dev);
 	mtx_unlock(&Giant);
 	pdev->pdrv->remove(pdev);
@@ -170,6 +180,7 @@ linux_pci_detach(device_t dev)
 	list_del(&pdev->links);
 	spin_unlock(&pci_lock);
 	put_device(&pdev->dev);
+	linux_clear_current(td);
 
 	return (0);
 }
@@ -179,13 +190,18 @@ linux_pci_suspend(device_t dev)
 {
 	struct pm_message pm = { };
 	struct pci_dev *pdev;
+	struct task_struct t;
+	struct thread *td;
 	int err;
 
+	td = curthread;
+	linux_set_current(td, &t);
 	pdev = device_get_softc(dev);
 	if (pdev->pdrv->suspend != NULL)
 		err = -pdev->pdrv->suspend(pdev, pm);
 	else
 		err = 0;
+	linux_clear_current(td);
 	return (err);
 }
 
@@ -193,13 +209,18 @@ static int
 linux_pci_resume(device_t dev)
 {
 	struct pci_dev *pdev;
+	struct task_struct t;
+	struct thread *td;
 	int err;
 
+	td = curthread;
+	linux_set_current(td, &t);
 	pdev = device_get_softc(dev);
 	if (pdev->pdrv->resume != NULL)
 		err = -pdev->pdrv->resume(pdev);
 	else
 		err = 0;
+	linux_clear_current(td);
 	return (err);
 }
 
@@ -207,13 +228,18 @@ static int
 linux_pci_shutdown(device_t dev)
 {
 	struct pci_dev *pdev;
+	struct task_struct t;
+	struct thread *td;
 
+	td = curthread;
+	linux_set_current(td, &t);
 	pdev = device_get_softc(dev);
 	if (pdev->pdrv->shutdown != NULL) {
 		DROP_GIANT();
 		pdev->pdrv->shutdown(pdev);
 		PICKUP_GIANT();
 	}
+	linux_clear_current(td);
 	return (0);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605240746.u4O7kLLi085991>