From 70401a9918e0810e7b0784fa6e1bdc766df20352 Mon Sep 17 00:00:00 2001 From: Levente Kurusa Date: Fri, 11 Apr 2014 19:12:13 +0200 Subject: [PATCH] qr: print_oops: implement scaling Allow the scaling of QR codes by the qr_oops kernel parameter. Also, implement safe guard against those who try a scale which wouldn't fit on screen. Signed-off-by: Levente Kurusa --- kernel/print_oops.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/kernel/print_oops.c b/kernel/print_oops.c index f0a3513..f7b19f2 100644 --- a/kernel/print_oops.c +++ b/kernel/print_oops.c @@ -54,7 +54,25 @@ static inline int compute_w(struct fb_info *info, int qrw) int xres = info->var.xres; int yres = info->var.yres; int minxy = (xres < yres) ? xres : yres; - return minxy / qrw / 3; + int ret = minxy / 3; + + /* try to apply scaling */ + ret *= qr_oops; + if (ret > xres || ret > yres) { + /* loop until we find the maximum we can use */ + while (qr_oops > 1) { + ret /= qr_oops; + qr_oops--; + ret *= qr_oops; + if (ret <= xres && ret <= yres) + goto exit; + } + printk(KERN_WARNING "Was unable to find suitable scaling!\n"); + return 0; + } + +exit: + return ret / qrw; } static int __init qr_compr_init(void) -- 1.8.3.1