mirror of
https://github.com/X11Libre/xserver.git
synced 2026-04-14 17:18:09 +00:00
fbdevhw: Use a wrapper around open()
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
This commit is contained in:
committed by
Enrico Weigelt
parent
d1deec0008
commit
c6d39ecc3f
@@ -235,10 +235,12 @@ fbdev2xfree_timing(struct fb_var_screeninfo *var, DisplayModePtr mode)
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* open correct framebuffer device */
|
||||
|
||||
|
||||
/* Wrapper around open() that also get the framebuffer name */
|
||||
static int
|
||||
fbdev_set_name(int scrnIndex, int fd, char **namep, Bool print_warning, Bool close_fd_on_error)
|
||||
fbdev_open_device(int scrnIndex, const char *dev, char **namep)
|
||||
{
|
||||
struct fb_fix_screeninfo fix;
|
||||
int fd = dev ? open(dev, O_RDWR) : -1;
|
||||
|
||||
if (!namep) {
|
||||
return fd;
|
||||
@@ -248,17 +250,14 @@ fbdev_set_name(int scrnIndex, int fd, char **namep, Bool print_warning, Bool clo
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct fb_fix_screeninfo fix;
|
||||
|
||||
if (ioctl(fd, FBIOGET_FSCREENINFO, (void *) (&fix)) == -1) {
|
||||
*namep = NULL;
|
||||
if (print_warning) {
|
||||
xf86DrvMsg(scrnIndex, X_ERROR,
|
||||
"FBIOGET_FSCREENINFO: %s\n", strerror(errno));
|
||||
}
|
||||
if (close_fd_on_error) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
return fd;
|
||||
xf86DrvMsg(scrnIndex, X_ERROR,
|
||||
"Not using framebuffer device %s: FBIOGET_FSCREENINFO: %s\n", dev, strerror(errno));
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
*namep = malloc(16);
|
||||
if (*namep) {
|
||||
@@ -272,21 +271,15 @@ fbdev_check_user_devices(int scrnIndex, const char* dev, char **namep)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (namep) {
|
||||
*namep = NULL;
|
||||
}
|
||||
|
||||
/* try argument (from XF86Config) first */
|
||||
if (dev) {
|
||||
fd = open(dev, O_RDWR);
|
||||
}
|
||||
else {
|
||||
fd = fbdev_open_device(scrnIndex, dev, namep);
|
||||
} else {
|
||||
/* second: environment variable */
|
||||
dev = getenv("FRAMEBUFFER");
|
||||
fd = dev ? open(dev, O_RDWR) : -1;
|
||||
fd = fbdev_open_device(scrnIndex, dev, namep);
|
||||
}
|
||||
|
||||
fd = fbdev_set_name(scrnIndex, fd, namep, TRUE, FALSE);
|
||||
if (dev && fd == -1) {
|
||||
xf86DrvMsg(scrnIndex, X_ERROR,
|
||||
"Could not use the explicitly provided framebuffer: %s\n", dev);
|
||||
@@ -326,8 +319,7 @@ fbdev_open_pci(int scrnIndex, struct pci_device *pPci, const char *device, char
|
||||
close(fd);
|
||||
snprintf(filename, sizeof(filename), "/dev/fb%d", i);
|
||||
|
||||
fd = open(filename, O_RDWR);
|
||||
fd = fbdev_set_name(scrnIndex, fd, namep, FALSE, TRUE);
|
||||
fd = fbdev_open_device(scrnIndex, filename, namep);
|
||||
if (fd != -1) {
|
||||
return fd;
|
||||
}
|
||||
@@ -352,21 +344,20 @@ fbdev_open(int scrnIndex, const char *dev, char **namep)
|
||||
|
||||
/* try the default device symlink */
|
||||
dev = "/dev/fb";
|
||||
fd = open(dev, O_RDWR);
|
||||
fd = fbdev_open_device(scrnIndex, dev, namep);
|
||||
|
||||
/* last tries, framebuffers 0 through 7 */
|
||||
char devbuf[] = "/dev/fb0";
|
||||
for (int i = 0; i < 8 && fd == -1; i++) {
|
||||
devbuf[sizeof(devbuf) - 2] = i + '0';
|
||||
fd = open(devbuf, O_RDWR);
|
||||
fd = fbdev_open_device(scrnIndex, devbuf, namep);
|
||||
}
|
||||
|
||||
if (fd == -1) {
|
||||
xf86DrvMsg(scrnIndex, X_ERROR, "Unable to find a valid framebuffer device\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fbdev_set_name(scrnIndex, fd, namep, TRUE, TRUE);
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user