LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-06-2016, 12:15 PM   #1
patholden
LQ Newbie
 
Registered: Nov 2009
Posts: 3

Rep: Reputation: 0
IOCTL issues while porting from 2.4 to 4.1.6


I've been assigned the task of porting a driver from 2.4 to 4.1.6. I could move it to the latest kernel but am in the middle of debug so really don't want to rock the boat just yet. My problem is that I cannot get IOCTL working for the device. I keep getting -1 error with errno of ENOTTY (25). I'm including a snippet of the init code here. The init code creates 4 devices, I've tried to open all 4 with no luck on the IOCTL. Any suggestions?

Kernel driver:

static const struct file_operations lg_fops = {
.owner = THIS_MODULE,
.read = lg_read, /* lg_read */
.write = lg_write, /* lg_write */
.unlocked_ioctl = lg_ioctl, /* lg_ioctl */
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_lg_ioctl,
#endif
.open = simple_open, /* lg_open */
.release = lg_release, /* lg_release */
};

static int lg_dev_probe(struct platform_device *dev)
{
struct lg_dev *lg_devp;
int lg_major;
int lg_minor;
int rc;

// Obtain IO space for device (char-dev will own it)
if (request_region(LG_BASE, LASER_REGION, DEV_NAME) == NULL)
return(-EBUSY);
// allocate mem for struct device will work with
lg_devp = kzalloc(sizeof(struct lg_dev), GFP_KERNEL);
if (!lg_devp)
{
pr_err("kzalloc() failed for laser\n");
return(-ENOMEM);
}

lg_devp->lg_class = class_create(THIS_MODULE, DEV_NAME);
if (IS_ERR(lg_devp->lg_class))
{
rc = PTR_ERR(lg_devp->lg_class);
pr_err("AGS-LG: class_create failed rc %d\n", rc);
kfree(lg_devp);
return(rc);
}

lg_devp->pdev = dev;
spin_lock(&driver_lock);
lg_devp->dev_num = find_first_zero_bit(dev_mask, LG_NUM_DEVICES);
spin_unlock(&driver_lock);
set_bit(lg_devp->dev_num, dev_mask);
rc = alloc_chrdev_region(&lg_devp->lg_devt, 0, LG_NUM_DEVICES, DEV_NAME);
if (rc < 0)
{
pr_err("AGS-LG: failed to allocate char dev region\n");
return(rc);
}
scnprintf(lg_devp->name, sizeof(lg_devp->name), DEV_NAME);
dev_set_name(lg_devp->dev, "%s", DEV_NAME);
device_initialize(lg_devp->dev);
cdev_init(&lg_devp->cdev, &lg_fops);
lg_devp->cdev.owner = THIS_MODULE;
rc = cdev_add(&lg_devp->cdev, lg_devp->lg_devt, 1);
if (rc < 0)
{
pr_err("\nAGS-LG: cdev_add failed, rc %d\n", rc);
class_destroy(lg_devp->lg_class);
unregister_chrdev_region(lg_devp->lg_devt, 1);
return(rc);
}

lg_major = MAJOR(lg_devp->lg_devt);
lg_minor = MINOR(lg_devp->lg_devt);
lg_devp->dev = device_create(lg_devp->lg_class, NULL,
MKDEV(lg_major, lg_minor), lg_devp,
"%s%d",DEV_NAME,lg_minor);
rc = PTR_ERR(lg_devp->dev);
{
pr_err("AGS-LG: can't create device, major %d, minor %d, rc %d\n"
,lg_major, lg_minor, rc);
unregister_chrdev(lg_major, DEV_NAME);
class_destroy(lg_devp->lg_class);
kfree(lg_devp);
return(rc);
}

platform_set_drvdata(lg_devp->pdev, lg_devp);
dev_set_drvdata(lg_devp->dev, lg_devp);
lg_devp->dev->release = lg_dev_release;

// Set up the event timer but don't start it yet.
setup_timer(&lg_devp->lg_timer, lg_timeout, (unsigned long)lg_devp);
lg_devp->lg_timer.expires = 0;

/* move to 0,0 position */
lg_write_io_to_dac(0x4000,0x4000,0);
return(0);
}
static struct platform_driver lg_platform_driver = {
.driver = {
.name = DEV_NAME,
},
.probe = lg_dev_probe,
};

static int __init laser_init(void)
{
int rc;

rc = platform_driver_register(&lg_platform_driver);
if (rc)
{
pr_err("platform_driver_register laser, ret %d\n", rc);
return(rc);
}

laser_platdev = platform_device_alloc(DEV_NAME, -1);
if (!laser_platdev) {
rc = -ENOMEM;
platform_driver_unregister(&lg_platform_driver);
return(rc);
}

laser_platdev->num_resources = 0;
laser_platdev->dev.driver = &lg_platform_driver.driver;
laser_platdev->dev.release = lg_dev_release;

if ((rc = platform_device_add(laser_platdev)) < 0)
{
platform_device_put(laser_platdev);
platform_driver_unregister(&lg_platform_driver);
return(rc);
}
dev_info(&laser_platdev->dev, "\nAGS-LG:Laser Guide Controller installed, rc %d.\n",rc);
return(rc);
}
 
Old 01-06-2016, 01:16 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 & 7
Posts: 3,274

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
I'm confused. Is the error happening in the init code or the ioctl code?
The error ENOTTY usually means "inappropriate ioctl for device" which most likely means the ioctl is being called incorrectly.

If you want help with an error, please post the whole error, properly formatted.
 
Old 01-06-2016, 02:18 PM   #3
patholden
LQ Newbie
 
Registered: Nov 2009
Posts: 3

Original Poster
Rep: Reputation: 0
I'm sorry, I didn't mean to confuse anyone. I forgot to post snippet from user-space code, which is where the error is happening:

IOCTL define example:
#define LG_IOCNUM 0xE1
#define LGSETQCCOUNTER _IOW(LG_IOCNUM, 0xB8, int)

User-space app code example:

int qcCount=-1;

fd = open("/dev/laser", O_RDWR);
if (fd <=0)
return(-1);
itest = ioctl(fd, LGSETQCCOUNTER, qcCount);
return(itest);


When I run user-space app, I get IOCTL failure -1 errno ENOTTY
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues with using ioctl and SIOCGARP to get ARP entry on Linux Kernal bostan Programming 1 08-04-2014 10:59 AM
Porting issues from RHEL4(2.6.9-55) to RHEL6(2.6.32-220) mkranjit Programming 3 08-18-2012 01:02 AM
Issues porting c program from SUSE to Redhat v9.2 serconsult Programming 11 07-31-2008 04:28 AM
How to pass IOCTL arguments from usespace ioctl call devkpict Linux - Kernel 1 12-07-2007 07:45 PM
porting issues from solaris to linux vinod_indus Programming 2 09-12-2005 12:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration